Issue
I am struggling to get a single stacked bar chart using matplotlib.
I want to create something like this: Horizontal Stacked Bar Chart
However, even if I use df.plot.barh(stacked=True, ax=axes_var, legend=False)
I get two separate bars. My data frame currently looks like this:
Percentage
Female 42.9
Male 57.1
Any advice would be appreciated.
Solution
First transpose one column DataFrame:
df.T.plot.barh(stacked=True, legend=False)
If 2 or more columns:
df[['Percentage']].T.plot.barh(stacked=True, legend=False)
Answered By - jezrael
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.