我有7个箱子的堆叠箱子:
labels = ['Digits', 'digits+spec-char', 'letters', 'letters+digit','letters+special-char','All-alphabet','All-alphabet(lower+upper)']
对于4个标签:
'CRNN', 'CRNN+transfer learning','CRNN+Image aug','CRNN+ Img Aug+ transfer learning'
我的情节有效,但仅显示CRNN+transfer learning
和CRNN+ Img Aug+ transfer learning
的分档,如下图所示。
这是我的代码:
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 + Image aug','CRNN + Img Aug +转学习'所以4种颜色而不是只有两种
EDIT1 我在添加后得到以下内容:
OCR_Engine =(97.12,97.68,96.76,96.64,96.30,96.51,96.11) p5 = plt.bar(ind + 4 * width,OCR_Engine,width)
谢谢
答案 0 :(得分:0)
目前,您正在将条形图直接绘制在彼此之上。您可以通过设置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()
如果您想要并排显示条形图,则只需调整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)