text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

titanic_df = pd.read_csv('/kaggle/input/titanic/train.csv')
test_df = pd.read_csv('/kaggle/input/titanic/test.csv')

plt.rcParams['figure.figsize'] = (15, 10)
fig, axes = plt.subplots(nrows=2, ncols=2)
ax0, ax1, ax2, ax3 = axes.flatten()
lived = titanic_df.loc[titanic_df['Survived'] == 1, 'Age']
died = titanic_df.loc[titanic_df['Survived'] == 0, 'Age']
ax0.hist([lived, died], stacked=True)
ax0.legend(['Lived', 'Died'])
ax0.set_title('Age')
lived = titanic_df.loc[titanic_df['Survived'] == 1, 'Pclass']
died = titanic_df.loc[titanic_df['Survived'] == 0, 'Pclass']
ax1.hist([lived, died], stacked=True)
ax1.legend(['Lived', 'Died'])
ax1.set_title('Class (1 = Highest)')
lived = titanic_df.loc[titanic_df['Survived'] == 1, 'Fare']
died = titanic_df.loc[titanic_df['Survived'] == 0, 'Fare']
ax2.hist([lived, died], stacked=True)
ax2.legend(['Lived', 'Died'])
ax2.set_title('Fare')
lived = titanic_df.loc[titanic_df['Survived'] == 1, 'Sex']
died = titanic_df.loc[titanic_df['Survived'] == 0, 'Sex']
ax3.hist([lived, died], stacked=True)
ax3.legend(['Lived', 'Died'])
ax3.set_title('Gender')