如何在柱状图上画误差棒,并且能够调整误差棒颜色大小,增加横线
效果如图:
代码如下:
import numpy as np
import matplotlib.pyplot as plt
y= np.random.rand(5) * 10
x = np.arange(1, len(y)+1)/2
y_err = np.std(y)
fig, ax = plt.subplots(figsize=(6,5), dpi=80)
err_attr={"elinewidth":2,"ecolor":"black","capsize":6}
bar1 = ax.bar(x, y, yerr=y_err, error_kw=err_attr,color = ['#FF5151','#613453', '#A32456','#D23d24','#88E0EF'], width=0.25)
ax.set_ylim(bottom=0.5)
ax.set_ylabel("Y", color='black', fontsize=20)
ax.tick_params(axis='y', labelcolor='black', labelsize=15)
ax.set_xticks(x)
legends = ['SVM','CNN','Method1','Method2','Method3']
ax.set_xticklabels(legends, fontsize=15)
plt.tight_layout()
plt.show()