欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

matplotlib条形图

程序员文章站 2022-04-21 15:02:34
...
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条形图

相关标签: matplotlib