matplotlib条形图

from matplotlib import pyplot as plt
import numpy as np
fig=plt.figure()
ax=fig.add_subplot(111)
x=np.arange(4)
data=np.array([15,20,18,25])
rect=ax.bar(x,data,width=0.5,color="lightblue")
for rec in rect:#添加数值
    x=rec.get_x()
    height=rec.get_height()
    ax.text(x+0.1,1.02*height,str(height))
ax.set_xticks([0,1,2,3])
ax.set_xticklabels(("first","second","third","fourth"))
ax.set_ylabel("sales")
ax.set_title("The Sales in 2016")
ax.grid(True)
ax.set_ylim(0,28)

matplotlib条形图_第1张图片

你可能感兴趣的:(python数据挖掘,可视化)