How to create stack of bar plot in python?

ipython

#1

I am currently learning about plotting of bar plots in python . I have created a Data frame and plot it to get a bar plot. But I want to know how to create the stack of bar plot .

df = DataFrame(np.random.rand(6, 4),
…: index=[‘one’, ‘two’, ‘three’, ‘four’, ‘five’, ‘six’],
…: columns=pd.Index([‘A’, ‘B’, ‘C’, ‘D’], name=‘Genus’))
df.plot(kind=‘bar’)


#2

@sid100158,

Use “Stacked=True” in df.plot(kind=‘bar’,stacked=True) for stacked bar chart.

import pandas as pd
import numpy as np
%matplotlib inline
df = pd.DataFrame(np.random.rand(6, 4), index=['one', 'two', 'three', 'four', 'five', 'six'],columns=pd.Index(['A', 'B', 'C', 'D'], name='Genus'))
ax = fig.add_subplot(111)
df.plot(kind='bar',stacked=True)

Hope this helps!

Regards,
Imran