【发布时间】:2018-03-31 10:05:22
【问题描述】:
我有以下代码来生成多年来给定月份的每日降雨量条形图。
df=pd.read_excel(("C:/Filepath/RainData.xls"), \
sheetname=sheet,\
header=0,\
parse_cols="B:BD",\
na_values='T')
precip = df.loc[31, :]
precipavg=((sum(precip[1:]))/(len(precip[1:])))
print(precipavg)
df.head(0)
fig,ax= plt.subplots()
precip.plot(kind="bar",ax=ax, color='g',figsize=(15,7))
plt.minorticks_on()
ax.tick_params(axis='x',which='minor',bottom='off')
ax.set_xlabel("Year")
ax.set_ylabel("Precipitation")
ax.set_title((filename+" Precipitation"), fontsize=20)
然后,我想在此条形图顶部添加一条线,表示该月的平均降雨量。我使用上面的 precipavg 行计算了这个。谢谢。
【问题讨论】:
标签: python excel pandas matplotlib