In [1]:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# Read data
df = pd.read_csv('Gaming and Mental Health.csv')

# Define how we will slice and loop over the data
loop_1 = df['gaming_platform'].unique()
loop_2 = df['gender'].unique()

# Create our plot object
fig, axs = plt.subplots(nrows=len(loop_1), ncols=len(loop_2), sharey=True, sharex=True, figsize=(4*len(loop_2), 3*len(loop_1)))

# Loop through the lists
for i, platform in enumerate(loop_1):
    for j, gender in enumerate(loop_2):
        # Slice the data
        df_sub = df[(df['gaming_platform'] == platform) & (df['gender'] == gender)]
        # Plot the data
        sns.boxplot(data=df_sub, x='game_genre', y='daily_gaming_hours', ax=axs[i, j])
        # Styling of subplot
        axs[i, j].set_xlabel(f'{gender}')
        axs[i, j].set_ylabel(f'{platform}')
        axs[i, j].xaxis.set_tick_params(rotation=90, labelsize=8)

# Styling of figure
plt.suptitle('Daily gaming hours per gaming platform and gender')
plt.subplots_adjust(bottom=0.1, top=0.95)
plt.show()
No description has been provided for this image