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

4个标签的堆叠箱子:仅显示两个标签

  •  0
  • helene  · 技术社区  · 9 年前

    l有7个堆叠的箱子,分别是:

    labels = ['Digits', 'digits+spec-char', 'letters', 'letters+digit','letters+special-char','All-alphabet','All-alphabet(lower+upper)']
    

    'CRNN', 'CRNN+transfer learning','CRNN+Image aug','CRNN+ Img Aug+ transfer learning'
    

    我的情节可行,但只显示用于 CRNN+transfer learning CRNN+ Img Aug+ transfer learning 如下图所示。 plot

    def bins_accuracy():
        import numpy as np
        import matplotlib.pyplot as plt
        from matplotlib.ticker import FormatStrFormatter
    
    
    
        N = 7
        fig, ax = plt.subplots()
    
        ax.yaxis.set_major_formatter(FormatStrFormatter('%.2f'))
        CRNN = (94.52,93.27, 94.34, 94.51,93.43,94.26,90)
    
        CRNN_transfer = (96.40,96.61,97.40,96.99,93.50,95.69,92.65)
        CRNN_img_aug=(0,0,0,0,0,94,92)
        CRNN_img_aug_transfer=(0,0,0,0,0,95,93)
    
    
        ind = np.arange(N)  # the x locations for the groups
        width = 0.35  # the width of the bars: can also be len(x) sequence
        labels = ['Digits', 'digits+spec-char', 'letters', 'letters+digit','letters+special-char','All-alphabet','All-alphabet(lower+upper)']
        p1 = plt.bar(ind, CRNN, width)
        p2 = plt.bar(ind, CRNN_transfer, width)
        p3 = plt.bar(ind, CRNN_img_aug, width)
        p4 = plt.bar(ind, CRNN_img_aug_transfer, width)
    
        plt.ylabel('Accuracy %')
        plt.title('Accuracy by group')
        plt.xticks(ind, ('Digits', 'digits+spec-char', 'letters', 'letters+digit','letters+special-char','All-alphabet','All-alphabet(lower+upper)'))
        plt.ylim(ymax=99, ymin=91)
        plt.legend((p1[0], p2[0],p3[0],p4[0]), ('CRNN', 'CRNN+transfer learning','CRNN+Image aug','CRNN+ Img Aug+ transfer learning'))
    
        plt.show()
    

    我想在我的情节中看到的是 “CRNN”、“CRNN+转移学习”、“CRNN+图像aug”、“CRNN+Img aug+转移学习”因此有4种颜色,而不是只有两种颜色

    编辑1

    OCR_引擎=(97.12、97.68、96.76、96.64、96.30、96.51、96.11) p5=plt。条形图(ind+4*宽度,OCR\U引擎,宽度)

    output

    非常感谢。

    1 回复  |  直到 9 年前
        1
  •  0
  •   Paul Brodersen    9 年前

    目前,您正在将这些条直接绘制在彼此的顶部。可以通过设置 bottom 关键词:

    import numpy as np
    import matplotlib.pyplot as plt
    
    N=7
    
    fig, ax = plt.subplots()
    
    CRNN = np.array([94.52,93.27, 94.34, 94.51,93.43,94.26,90])
    CRNN_transfer = np.array([96.40,96.61,97.40,96.99,93.50,95.69,92.65])
    CRNN_img_aug = np.array([0,0,0,0,0,94,92])
    CRNN_img_aug_transfer= np.array([0,0,0,0,0,95,93])
    
    ind = np.arange(N)  # the x locations for the groups
    width = 0.35  # the width of the bars: can also be len(x) sequence
    p1 = plt.bar(ind, CRNN, width)
    p2 = plt.bar(ind, CRNN_transfer, width, bottom=CRNN)
    p3 = plt.bar(ind, CRNN_img_aug, width, bottom=CRNN+CRNN_transfer)
    p4 = plt.bar(ind, CRNN_img_aug_transfer, width, bottom=CRNN+CRNN_transfer+CRNN_img_aug)
    
    plt.show()
    

    enter image description here

    如果你想让这些条并排排列,你只需要调整x位置。

    # side-by-side
    fig, ax = plt.subplots()
    ind = np.arange(0, 2*N, 2)  # the x locations for the groups
    p1 = plt.bar(ind, CRNN, width)
    p2 = plt.bar(ind+width, CRNN_transfer, width)
    p3 = plt.bar(ind+2*width, CRNN_img_aug, width)
    p4 = plt.bar(ind+3*width, CRNN_img_aug_transfer, width)
    

    enter image description here

    推荐文章