I want to create a stacked bar plot of the titanic dataset. The plot needs to group by "Pclass", "Sex" and "Survived". I have managed to do this with a lot of tedious numpy manipulation to produce the normalized plot below (where "M" is male and "F" is female)
Is there a way to do this using pandas inbuilt plotting functionality?
I have tried this:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('train.csv')
df_grouped = df.groupby(['Survived','Sex','Pclass'])['Survived'].count()
df_grouped.unstack().plot(kind='bar',stacked=True, colormap='Blues', grid=True, figsize=(13,5));
Which is not what I want. Is there anyway to produce the first plot using pandas plotting? Thanks in advance



