为了账号安全,请及时绑定邮箱和手机立即绑定

在时间序列图中添加计数列

在时间序列图中添加计数列

慕无忌1623718 2022-07-26 16:38:44
我想根据月份和年份绘制平均值。我的数据有两列(计数,平均值)和日期作为索引。如图所示,这是一个类似于我的情节的情节,其中 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')

//img1.sycdn.imooc.com//62dfa84300018aef05920311.jpg

查看完整回答
反对 回复 2022-07-26
  • 1 回答
  • 0 关注
  • 150 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号