我想根据月份和年份绘制平均值。我的数据有两列(计数,平均值)和日期作为索引。如图所示,这是一个类似于我的情节的情节,其中 x 是年,y 是平均值这是我的代码 import matplotlib.pyplot as plt diet = df[['mean']] diet.plot(figsize=(20,10), linewidth=5, fontsize=20 ,marker='<') plt.xlabel('Year', fontsize=20); plt.xlabel('Month/Year') plt.ylabel('mean')有没有办法像这样在所有点线上添加计数列以了解每个月的计数。
1 回答
慕工程0101907
TA贡献1887条经验 获得超5个赞
idx = pd.date_range(start='1901-01-01', end='1903-12-31', freq='1M')
df = pd.DataFrame({"mean": np.random.random(size=(idx.size,)), "count": np.random.randint(0,10, size=(idx.size,))}, index=idx)
plt.figure()
ax = df['mean'].plot(figsize=(8,4))
for d,row in df.iterrows():
ax.annotate('{:.0f}'.format(row['count']), xy=(d,row['mean']), ha='center')

添加回答
举报
0/150
提交
取消
