Subplots using Python in Excel
Channel: Abiola David
Date: 28/08/2023

This second video demo how to create subplots using Python in Excel

#Excel #PythonInExcel

Python Code
df = xl("A2:J1041", headers=True)
cat_var = ['City', 'Payment_Type', 'Account_Manager']
fig, axs = plt.subplots(nrows=1, ncols=3, figsize=(30, 20))
axs = axs.flatten()
common_fontsize = 20

for i, var in enumerate(cat_var):
    sns.countplot(x=var, hue='Region', data=df, ax=axs[i])
    axs[i].set_xticklabels(axs[i].get_xticklabels(), rotation=90)
    axs[i].tick_params(axis='x', labelsize=common_fontsize)
    axs[i].tick_params(axis='y', labelsize=common_fontsize)
    axs[i].legend(fontsize=common_fontsize)
    axs[i].set_xlabel(f'{var}', fontsize=common_fontsize + 2)
    axs[i].set_ylabel('Count', fontsize=common_fontsize + 2)
fig.suptitle('Categorical Data Analysis', fontsize=common_fontsize + 4)

fig.tight_layout()
plt.show()