【发布时间】:2017-03-12 21:08:18
【问题描述】:
我正在尝试在一个绘图上绘制多个电器的温度。
数据来自下面的dataframe df,我先创建日期列作为索引。
df=df.set_index('Date')
Date Appliance Value (degrees)
2016-07-05 03:00:00 Thermometer 22
2016-08-06 16:00:00 Thermometer . 19
2016-12-07 21:00:00 . Thermometer . 25
2016-19-08 23:00:00 . Thermostat . 21
2016-25-09 06:00:00 . Thermostat . 20
2016-12-10 21:00:00 . Thermometer . 18
2016-10-11 21:00:00 . Thermostat . 21
2016-10-12 04:00:00 . Thermometer . 20
2017-01-01 07:00:00 . Thermostat . 19
2017-01-02 07:00:00 . Thermometer . 23
我们希望能够显示 2 条曲线:一条是温度计的温度,另一条是恒温器的温度,有 2 种不同颜色,随时间变化。
plt.plot(df.index, [df.value for i in range(len(appliance)]
ax = df.plot()
ax.set_xlim(pd.Timestamp('2016-07-05'), pd.Timestamp('2015-11-30'))
ggplot 更适合这个吗?
我无法做到这一点
【问题讨论】:
标签: python pandas matplotlib plot