Reputation: 117
I have a pandas dataframe as below.
I want to be able to plot the barchart with the same Names on the same stacked bar and colored differently like this:
Thanks for any help Jason
Upvotes: 0
Views: 56
Reputation: 150745
Not totally colored as you want, but you can use this as a start:
df = pd.DataFrame({'Name':['R1','T1','Y1','R1','T2','T1'],
'volume':[10,15,12,12,5,2]})
(df.assign(c=df.groupby('Name').cumcount())
.pivot(index='Name', columns='c',values='volume')
.plot.bar(stacked=True)
)
Output:
Upvotes: 1