python实现多条柱状图对比输出?


import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"]=["SimHei"]#输出图像的标题可以为中文正常输出
plt.rcParams["axes.unicode_minus"]=False #可以正常输出图线里的负号
name_list = ["评分1","评分2'","评分3", "评分4"]
num_list = [0.912,0.914,0.957,0.851]
num_list1 = [0.976, 0.914,0.916,0.734]

x = list(range(len(num_list)))
total_width, n = 0.6, 3
width = total_width / n
plt.bar(x, num_list, width=width, label="LogisticRegression", fc = "b")

plt.text(x[0],num_list[0],"91.2%",ha='center',va='bottom',fontsize=10)
plt.text(x[1],num_list[1],"91.4%",ha='center',va='bottom',fontsize=10)
plt.text(x[2],num_list[2],"96.7%",ha='center',va='bottom',fontsize=10)
plt.text(x[3],num_list[3],"85.1%",ha='center',va='bottom',fontsize=10)

for i in range(len(x)):
x[i] = x[i] + width
plt.bar(x, num_list1, width=width, label="RandomForest", tick_label = name_list, fc ="r")
plt.xlabel("不同评分目标类型",fontsize=12)
plt.ylabel("不同模型的准确率大小",fontsize=12)
plt.title("不同评分结果的机器学习算法模型精度表现",fontsize=15)

plt.text(x[0],num_list1[0],"97.6%",ha='center',va='bottom',fontsize=10)
plt.text(x[1],num_list1[1],"91.4%",ha='center',va='bottom',fontsize=10)
plt.text(x[2],num_list1[2],"91.6%",ha='center',va='bottom',fontsize=10)
plt.text(x[3],num_list1[3],"73.4%",ha='center',va='bottom',fontsize=10)

plt.legend(fontsize=9)
plt.show()


import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"]=["SimHei"]#输出图像的标题可以为中文正常输出
plt.rcParams["axes.unicode_minus"]=False #可以正常输出图线里的负号
name_list = ["评分1","评分2'","评分3", "评分4"]
num_list = [0.912,0.914,0.957,0.851]
num_list1 = [0.976, 0.914,0.90,0.734]
x = list(range(len(num_list)))
total_width, n = 0.6, 2
width = total_width / n
plt.bar(x, num_list, width=width, label="LogisticRegression", fc = "b")
for a,b in zip(x,num_list): #柱子上的数字显示
plt.text(a,b,'%.3f'%b,ha='center',va='bottom',fontsize=10);
for i in range(len(x)):
x[i] = x[i] + width
plt.bar(x, num_list1, width=width, label="RandomForest", tick_label = name_list, fc ="r")
plt.xlabel("不同评分目标类型",fontsize=10)
plt.ylabel("不同模型的准确率大小",fontsize=10)
plt.title("不同评分结果的机器学习算法模型精度表现",fontsize=15)
for a,b in zip(x,num_list1): #柱子上的数字显示
plt.text(a,b,'%.3f'%b,ha='center',va='bottom',fontsize=10);
plt.legend(fontsize=8)
plt.show()

 

 



posted @ 2020-08-02 17:26  The-Chosen-One  阅读(5260)  评论(0编辑  收藏  举报