简体   繁体   English

使用大量数据点绘制时间序列matplotlib

[英]Plot time series matplotlib with lots of data points

I want to plot a time series for a dataset which has data for 12 months. 我想为一个具有12个月数据的数据集绘制一个时间序列。 However the data is recorded for every hour of every day for the 12months. 但是,将记录12个月中每天每小时的数据。 The whole dataset is over 8000 datapoints. 整个数据集超过8000个数据点。 The data is in the following format 数据格式如下

        Date   Time  Energy
0 2014-01-01   1     1118.1
1 2014-01-01   2     1233.2
2 2014-01-01   3     1278.2
.     .        .      .  
23 2014-01-01  24    1125.3
24 2014-01-02  1     1213.3
.    .         .      .

When I plot it like this 当我这样绘制时

plt.plot(energy['Date'], energy['Energy'])
plt.xlabel('Date')
plt.ylabel('Energy')

I get the following output 我得到以下输出 时间序列

This graph doesn't make much sense because I cant observe any trends. 该图没有太大意义,因为我无法观察任何趋势。 I instead want to plot the average energy for each day. 相反,我想绘制每天的平均能量。 Any other suggestions about how to plot this time series in such a way that I observe any trends is welcome 任何其他建议如何以我观察任何趋势的方式绘制此时间序列的建议都值得欢迎

You need groupby with aggregating mean first: 您需要首先使用汇总mean groupby

energy = energy.groupby('Date')['Energy'].mean()

and then Series.plot : 然后是Series.plot

energy.plot()

All together: 全部一起:

energy.groupby('Date')['Energy'].mean().plot()

IIUC: IIUC:

you need to sort 你需要排序

energy = energy.sort_values(['Date', 'Time'])
plt.plot(energy['Date'], energy['Wind Generation'])
plt.xlabel('Date')
plt.ylabel('Energy')
plt.autofmt_xdate()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM