代码之家  ›  专栏  ›  技术社区  ›  Stupid420

如何用条形图值绘制条形图?

  •  0
  • Stupid420  · 技术社区  · 8 年前

    0 我每个酒吧的价值。

    from __future__ import division
    import matplotlib.pyplot as plt
    import numpy as np
    
    x = [0,1,2,3,4,5,6,7,8,9,10,11,12]
    freq = [0.93, 0.87,0.86,0.87,0.93,0.84,0.74,0.79,0.78,0.95,0.88,0.8, 0.71]
    
    width = 0.5 # width of the bars
    
    fig, ax = plt.subplots()
    rects1 = ax.bar(x, freq, width, color='r')
    
    ax.set_ylim(0,1)
    ax.set_ylabel('auc-roc')
    
    ax.set_xticks(np.add(x,(width/2.2))) # set the position of the x ticks
    ax.set_xticklabels(('X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9', 'X10', 'X11', 'X12', 'X13'))
    
    def autolabel(rects):
    
        for rect in rects:
            height = rect.get_height()
            ax.text(rect.get_x() + rect.get_width()/2., 1.0*height,
                '%d' % (height),
                ha='center', va='bottom')
    
    autolabel(rects1)
    
    plt.show()
    

    Image with 0 bar values

    1 回复  |  直到 8 年前
        1
  •  2
  •   Stefan Falk    8 年前
    '%d' % (height),
    

    我认为这将值映射到整数。在您的情况下,值被运行到 0 .

    %f 或者更确切地说 %.2f .

    enter image description here