python的并列柱形图_Python画并列柱状图

在利用柱状图比较不同实验结果时,有时我们可能要比较多个指标。如下例,每组实验都需要体现AUC和MAP两个指标。此时,使用并列柱状图可以更高的呈现结果。

import numpy as np

import matplotlib.pyplot as plt

import matplotlib as mpl

import seaborn as sns

sns.set(color_codes=True)

mpl.rcParams["font.sans-serif"] = ["SimHei"]

mpl.rcParams["axes.unicode_minus"] = False

#柱高信息

Y = [0.87,0.878,0.872,0.885,0.876]

Y1 = [0.618,0.634,0.637,0.638,0.629]

X = np.arange(len(Y))

bar_width = 0.25

tick_label = ['A','B','C','D','E','F']

#显示每个柱的具体高度

for x,y in zip(X,Y):

plt.text(x+0.005,y+0.005,'%.3f' %y, ha='center',va='bottom')

for x,y1 in zip(X,Y1):

plt.text(x+0.24,y1+0.005,'%.3f' %y1, ha='center',va='bottom')

#绘制柱状图

plt.bar(X, Y, bar_width, align="center", color="red", label="AUC", alpha=0.5)

plt.bar(X+bar_width, Y1, bar_width, color="purple", align="center", \

label="MAP", alpha=0.5)

plt.xlabel("X")

plt.ylabel("Y")

plt.title('Picture Name')

plt.xticks(X+bar_width/2, tick_label)

#显示图例

plt.legend()

#plt.show()

plt.savefig('result.png',dpi = 400)

效果图如下所示:

result.png

你可能感兴趣的:(python的并列柱形图)