Ija*_*him 5 plot matplotlib dataframe python-3.x pandas
我有多个具有不同年份数据的数据框。
数据框中的数据是:
>>> its[0].head(5)
Crocs
date
2017-01-01 46
2017-01-08 45
2017-01-15 43
2017-01-22 43
2017-01-29 41
>>> its[1].head(5)
Crocs
date
2018-01-07 23
2018-01-14 21
2018-01-21 23
2018-01-28 21
2018-02-04 25
>>> its[2].head(5)
Crocs
date
2019-01-06 90
2019-01-13 79
2019-01-20 82
2019-01-27 82
2019-02-03 81
Run Code Online (Sandbox Code Playgroud)
我尝试将所有这些数据帧绘制在单个图形(图表)中,是的,我完成了,但这不是我想要的。
我使用以下代码绘制了数据框
>>> for p in its:
plt.plot(p.index,p.values)
>>> plt.show()
Run Code Online (Sandbox Code Playgroud)
只是我希望图表忽略年份并按月和日绘制
您可以尝试根据月份和日期将日期时间索引转换为时间序列整数并绘制
df3 = pd.concat(its,axis=1)
xindex= df3.index.month*30 + df3.index.day
plt.plot(xindex,df3)
plt.show()
Run Code Online (Sandbox Code Playgroud)
如果您想要日期时间信息而不是整数,您可以将 xticks 添加到框架
labels = (df3.index.month*30).astype(str)+"-" + df3.index.day.astype(str)
plt.xticks(df3.index.month*30 + df3.index.day, labels)
plt.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2419 次 |
| 最近记录: |