论文作图---不同分类模型准确率对比(柱状图)

进行五折交叉验证后,对不同模型的平均准确率可视化,代码如下

import matplotlib.colors as col
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np

mean_values = [0.912, 0.932, 0.922,0.934,0.911] #平均准确率
variance = [0.02, 0.04, 0.05,0.06,0.01]  #标准差
color= ['r','b','g','c','y']  #颜色设置
bar_label = ['model1', 'model2', 'model3','model4','model5']
x_pos = range(len(bar_label))  
cmap1 = cm.ScalarMappable(col.Normalize(min(mean_values), max(mean_values), cm.hot))
bars = plt.bar(x_pos, mean_values, yerr=variance, color=color)  
# bars = plt.bar(x_pos, mean_values, yerr=variance, color=cmap1.to_rgba(mean_values))  # yerr参数设定误差棒 ,alpha=0.3
plt.axhline(min(mean_values),linestyle=':')
for b, d in zip(bars, mean_values):
    # print((b.get_width(),b.get_height()))
    # print(b.get_x())
    plt.text( b.get_x() + b.get_width() / 2,b.get_height() +0.05,d)  # get_y是柱子最下面的数据,get_x是柱子最左边的数据
max_y = max(zip(mean_values, variance))  # 根据zip中的第一个数据判断大小
plt.ylim([0, (max_y[0] + max_y[1]) * 1.2])  # 设定y轴的取值范围
plt.ylabel('accuracy')  # 设定y轴标签
plt.xticks(x_pos, bar_label)  # 设定x轴刻度值
plt.savefig("bar of accuracy.jpg", dpi=600)
plt.show()

在这里插入图片描述颜色是真的丑啊,后面还需要调一下。
参考Python-总结笔记-数据可视化应用-Matplotlib-条形图bar/barh

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值