3

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.

Lenehan
  • 33
  • 3

1 Answers1

3

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)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252