matplotlib画柱状图

参考 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是两个列表,
画图结果:
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值