【发布时间】:2019-07-31 13:32:16
【问题描述】:
我有一个带有累积降雨数据的 pandas 数据框。
列是'dayoftheyear', '1981', '1982' .... '2019'
我使用以下代码绘制数据:
fig, ax = plt.subplots(1, 1, figsize=(10,10))
ax.set_title('Cummulative rainfall in Chennai hydrological basin')
ax.set_xlabel('day of the year')
ax.set_ylabel('total rainfall in mm')
ax.yaxis.tick_right()
ax.yaxis.set_label_position("right")
df.plot(ax=ax,
x='dayofyear',
y=years_string,
colormap='gray',
legend=False,
alpha=0.2)
df.plot(ax=ax,
x='dayofyear',
y=['2015','2016','2017','2018'],
alpha=0.7,
colormap='plasma')
df.plot(ax=ax,
x='dayofyear',
y='2019',
color='red',
linewidth=3)
fig.savefig('test.jpg')
但是,一年中的哪一天可能很难理解,如果可能的话,我想在每月和每月的哪一天添加主要的刻度线。我找到了这个resource 并试图让它工作无济于事。有没有一种简单的方法可以在不转换数据的情况下更改 xaxis 刻度?
完整代码here
【问题讨论】:
-
您可以将 dayofyear 列转换为真实日期。
标签: python pandas matplotlib