当前位置: 首页 > 图灵资讯 > 行业资讯> python直方图如何显示值?

python直方图如何显示值?

发布时间:2026-01-19 21:38:49

python直方图显示值的方法:

text()函数可以通过向直方图添加注释来显示值。

函数功能:添加图形内容细节的无指向注释文本

函数语法:

plt.text(x,y,string,weight="bold",color="b")

参数说明:

  • x: 注释文本内容所在位置的横坐标

  • y:注释文本内容所在位置的纵坐标

  • string:注释文本内容

  • weight:注释文本内容的粗细风格

  • color:注明文本内容的字体颜色

#-*-coding:utf-8-*-

importmatplotlib.pyplotasplt

#num_list=[1.5,0.6,7.8
fig,ax=plt.subplots()
num_list=[7870,81937,17529598,6225227]
name_list=['Eviction','Failed','Finished','Killed']
b=ax.bar(name_list,num_list)

plt.bar(range(len(num_list)),num_list,color='rbg',tick_label=name_list)

fora,binzip(name_list,num_list):
ax.text(a,b+1,b,ha='center',va='bottom')

plt.title('NumbersofFoureventtypes')
plt.xlabel('Eventtype')
plt.ylabel('Number')
plt.show()

效果如下:

请关注Python自学网了解更多Python知识。

相关文章

Python怎么把数字变成中文?

Python怎么把数字变成中文?

2026-01-22
python时间戳是啥意思?

python时间戳是啥意思?

2026-01-22
Python中的main函数解析

Python中的main函数解析

2026-01-22
python怎么判断是否为纯字母?

python怎么判断是否为纯字母?

2026-01-22
Python中的字典遍历有序吗?

Python中的字典遍历有序吗?

2026-01-22
python如何操作剪切板?

python如何操作剪切板?

2026-01-22