python直方图显示值的方法

这篇文章主要介绍python直方图显示值的方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

网站建设哪家好,找创新互联建站!专注于网页设计、网站建设、微信开发、小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了吉利免费建站欢迎大家使用!

python直方图显示值的方法:

可以使用text()函数通过为直方图添加注释的方法来显示值。

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

函数语法:

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

参数说明:

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

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

  • string:注释文本内容

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

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

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

import matplotlib.pyplot as plt
 
#num_list = [1.5,0.6,7.8,6]
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)

for a, b in zip(name_list, num_list):
    ax.text(a, b+1, b, ha='center', va='bottom')

plt.title('Numbers of Four eventtypes')
plt.xlabel('Eventtype')
plt.ylabel('Number')
plt.show()

效果如下:

python直方图显示值的方法

以上是python直方图显示值的方法的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


本文标题:python直方图显示值的方法
本文地址:http://myzitong.com/article/poiseh.html