如何使用matplotlib制作百分比堆积的条形图?

时间:2020-05-03 19:27:47

标签: python matplotlib

这是我的原始代码:

categories = df[(df['Title'].isin(Titles_top10))].groupby('Title').agg(np.sum).drop(['Regular', 'Total'], axis=1)

生成水平堆积的条形图

fig, ax = plt.subplots()
categories.plot.barh(stacked=True, rot=0, ax=ax)
ax.set_title('Total expenditure by earnings category\n(excluding \"regular\" and \"total")')
ax.set_ylabel('Total Expenditure')
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles[::-1], labels[::-1], prop={'size': 'small'},bbox_to_anchor=(1, 1.05))

plt.tight_layout()
plt.show()

情节如下所示: enter image description here

但是我想将其更改为堆积百分比条形图。我该怎么办?

0 个答案:

没有答案