TimK
TimK

Reputation: 99

Pandas / matplotlib stacked horizontal percentage barchart

enter image description here

df_new.plot(

kind = 'barh',
x = 'Measure',
stacked = True,
title = 'Stacked Bar Graph',
mark_right = True)

This gives me a key error on Measure - can't figure out why?

Upvotes: 0

Views: 31

Answers (1)

Timeless
Timeless

Reputation: 37747

You need to tranpose your dataframe with pandas.DataFrame.T to get one horizontal stacked bar:

Try this:

(
    df_new
      .T
      .plot(kind = 'barh',
            stacked = True,
            title = 'Stacked Bar Graph',
            mark_right = True)
)

# Output :

enter image description here

Upvotes: 1

Related Questions