• 技术文章 >常见问题 >Python常见问题

    python直方图如何显示值?

    yangyang2020-05-26 13:25:18原创8744

    python直方图显示值的方法:

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

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

    函数语法:

    1

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

    参数说明:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    # -*- 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
    上一篇:怎么用Python替换文件中的内容? 下一篇:在手机上如何写Python文本?

    相关文章推荐

    • python 基本数据类型及基本运算• python中怎么设置输出不带换行符?• python写界面的流行库

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网