Lenehan
Lenehan

Reputation: 33

Single Stacked Bar Chart Matplotlib

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.

Upvotes: 3

Views: 2518

Answers (1)

jezrael
jezrael

Reputation: 863651

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)

Upvotes: 3

Related Questions