python-matplotlib画图添加平均值线

#绘制柱状图
import matplotlib.pyplot as plt
import numpy as np
x=[1,2,3,4,5,6]
y=[3,4,5,6,7,8]
c=np.mean(y)
plt.bar(x,y,color="red",hatch="/",tick_label=["q","er","jjd","dd","kk","dd"])
plt.xlabel("x-axis",fontsize=15)
plt.ylabel("y-axis",fontsize=15)
plt.title("bar",fontsize=15)
plt.axhline(y=c,color="blue")
plt.show()

posted @ 2019-08-22 21:55  朵朵奇fa  阅读(4901)  评论(0编辑  收藏  举报