很多小伙伴想了解python直方图显示值的方法,那么今天小编就通过这篇文章来给大家详细介绍一下python直方图,和它显示值的操作方法,感兴趣的小伙伴可以仔细阅读完这篇文章。
如果我们想在python中显示直方图的值,那么我们就可以使用text()函数通过为直方图添加注释的方法来显示值。
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直方图显示值的方法,希望大家通过阅读小编的文章之后能够有所收获!如果大家觉得小编的文章不错的话,可以多多分享给有需要的人。