• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

python直方图如何显示值?

python 搞java代码 3年前 (2022-05-21) 28次浏览 已收录 0个评论

python直方图显示值的方法:

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

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

函数语法:

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

www#gaodaima.com来源gaodaimacom搞#^代%!码网搞代码

参数说明:

  • 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知识请关注搞代码网。

来源:搞代码网:原文地址:https://www.gaodaima.com


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python直方图如何显示值?

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址