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

我想根据月份和年份绘制平均值。

我的数据有两列(计数,平均值)和日期作为索引。

如图所示,这是一个类似于我的情节的情节,其中 x 是年,y 是平均值

http://img2.mukewang.com/62dfa8290001c96206310468.jpg

这是我的代码


    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')

有没有办法像这样在所有点线上添加计数列以了解每个月的计数。

http://img2.mukewang.com/62dfa8340001e0db05920467.jpg

慕无忌1623718
浏览 151回答 1
1回答

慕工程0101907

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():&nbsp; &nbsp; ax.annotate('{:.0f}'.format(row['count']), xy=(d,row['mean']), ha='center')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python