text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt
cols = ['Sex', 'Pclass', 'Age', 'SibSp']
n_rows = 2
n_cols = 2
fig, axs = plt.subplots(n_rows, n_cols, figsize=(n_cols * 8, n_rows * 8))
for r in range(0, n_rows):
    for c in range(0, n_cols):
        i = r * n_cols + c
        ax = axs[r][c]
        sns.countplot(df[cols[i]], hue=df['Survived'], ax=ax)
        ax.set_title(cols[i])
        ax.legend(title='survived', loc='upper right')
plt.tight_layout()