参考 https://blog.csdn.net/qq_29721419/article/details/71638912
x = list(range(len(truth_count_list)))
total_width, n = 0.5, 2
width = total_width / n
plt.bar(x, truth_count_list, width=width, label='groundtruth', fc='y') #width表示两个柱形的间隔
for i in range(len(x)):
x[i] = x[i] + width
plt.bar(x, pre_count_list, width=width, label='predict', tick_label=range_list, fc='r')
for x,y1,y2 in zip(x,truth_count_list,pre_count_list): # 在柱状图上显示具体数值
plt.text(x-0.3,y1, '%d' % y1, ha='center', va= 'bottom',fontsize=8)
plt.text(x+0.15,y2, '%d' % y2,ha='center', va= 'bottom',fontsize=8)
plt.legend()
plt.title(r'length of testing set', fontsize=20)
plt.text(5.5,175,r'total of groundtruth:{}'.format(len(length_true)),fontsize=10) #在坐标为(5.5,175)的位置处添加文字
plt.text(5.5,150,r'total of prediction:{}'.format(len(length_pre)),fontsize=10)
plt.savefig('/home/res.jpg')
plt.show()
其中truth_count_list和pre_count_list是两个列表,
画图结果: