在条形图中设置不同的颜色

时间:2021-03-09 16:58:49

标签: python python-3.x pandas matplotlib seaborn

x1 = df[['model', 'failure']].groupby('model').sum() # Total number of failures by model
x2 = df[['model', 'failure']].groupby('model').count() # Total number of each model
ptg_model_fail = np.divide(x1, x2) * 100 
ptg_model_fail.columns = ['ptg']
ptg_model_fail = ptg_model_fail.reset_index().sort_values('ptg')

fig, ax = plt.subplots(figsize=(7, 7))
ax.barh(ptg_model_fail['model'], ptg_model_fail['ptg'], color='cyan',edgecolor='k')
ax.set_xlabel('Percentage')
ax.set_title('Failure percentage by model', size=16)

plt.tight_layout()
plt.show()

enter image description here

如何使用不同的颜色和控制条的宽度来定义不同的模型?感谢您的时间!

0 个答案:

没有答案