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()
如何使用不同的颜色和控制条的宽度来定义不同的模型?感谢您的时间!