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条形图
最新推荐文章于 2024-03-14 16:08:49 发布
本文通过使用Matplotlib和NumPy库展示了一个条形图,该图表详细记录了2016年的销售数据,并为每个条形添加了具体的数值标签以便更直观地理解数据。同时设置了坐标轴标签、标题、网格线以及限制了Y轴的最大值。

623

被折叠的 条评论
为什么被折叠?



