我有一年的数据,我想画出它们的季节模式。所以我只是为每个季节创建了子数据。但我的冬季数据图有一个缺口。它不能按顺序画出三个月
以下是我的数据:
winter = pd.concat([countData19_gdf.loc['2019-12-01':'2019-12-31'], countData19_gdf.loc['2019-01-01':'2019-02-28']])
winter= winter.sort_index()
min_count = countData19_gdf['volume'].min()
max_count = countData19_gdf['volume'].max() + 20
fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(16,10))
line_width = 2
ax[0,0].plot(winter.resample('d').mean()['volume'].index, winter.resample('d').mean()['volume'], c='blue', lw=line_width);
ax[0,1].plot(countData19_gdf.loc['2019-03-01': '2019-05-31'].resample('d').mean()['volume'].index, countData19_gdf.loc['2019-03-01': '2019-05-31'].resample('d').mean()['volume'] ,c='orange',lw=line_width);
ax[1,0].plot(countData19_gdf.loc['2019-06-01': '2019-08-31'].resample('d').mean()['volume'].index, countData19_gdf.loc['2019-06-01': '2019-08-31'].resample('d').mean()['volume'], c='green', lw=line_width);
ax[1,1].plot(countData19_gdf.loc['2019-09-01': '2019-11-30'].resample('d').mean()['volume'].index, countData19_gdf.loc['2019-09-01': '2019-11-30'].resample('d').mean()['volume'], c='brown', lw=line_width);
ax[0,0].title.set_text('Winter')
ax[0,1].title.set_text('Spring')
ax[1,0].title.set_text('Summer')
ax[1,1].title.set_text('Fall')
for ax in [ax[0,1], ax[1,0], ax[1,1]]:
# Set minor ticks with day numbers
ax.xaxis.set_minor_locator(dates.DayLocator(interval=10))
ax.xaxis.set_minor_formatter(dates.DateFormatter('%d'))
# Set major ticks with month names
ax.xaxis.set_major_locator(dates.MonthLocator())
ax.xaxis.set_major_formatter(dates.DateFormatter('\n%b'))
plt.savefig('seasonal_global.png')
plt.show()
图中出现的间隙是因为显示了两个不同冬季的冬季月份,一个始于2018年,结束于2019年,另一个始于2019年,结束于2020年
您需要将数据子集,以便它收集适当的月份,如下代码所示:
它描绘了这一点:
如果你没有超过一年的数据,那么你可以用浅灰色的其他季节来填补空白,如下图所示:
我使用的合成数据比真实数据更不稳定。您可以使用
rolling()
使用移动平均平滑时间序列,以提高随时间变化的可读性相关问题 更多 >
编程相关推荐