0

Here is my original code:

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

generate horizontal stacked bar chart(s)

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()

The plot looks like this: enter image description here

But I want to change it to Stacked Percentage Bar Plot. How should I do that?

deadshot
  • 8,881
  • 4
  • 20
  • 39
Yalun Gao
  • 39
  • 5
  • There are many examples on the 'net. Here are two: https://chrisalbon.com/python/data_visualization/matplotlib_percentage_stacked_bar_plot/ and https://python-graph-gallery.com/13-percent-stacked-barplot/ – pink spikyhairman May 03 '20 at 19:43
  • Does this answer your question? [100% Stacked Bar Chart in MatPlotLib](https://stackoverflow.com/questions/43566956/100-stacked-bar-chart-in-matplotlib) – Patrick FitzGerald Dec 31 '20 at 19:58

0 Answers0