I have defined a function for me to analyse my columns with boxplots.
fig, ax = plt.subplots((len(list_of_columns)),1,figsize= datafigsize)
fig.suptitle(suptitle,fontsize=30)
ax = ax.ravel() # Ravel turns a matrix into a vector, which is easier to iterate
plt.tight_layout(h_pad = 3,pad=10);
for i, column in enumerate(list_of_columns):
nobs = dataframe[column].value_counts().values
nobs = [str(y) for y in nobs.tolist()]
nobs = ["n: " + j for j in nobs]
pos = range(len(nobs))
medians = dataframe.groupby([column])['saleprice'].median().values
for tick,label in zip(pos,ax[i].get_xticklabels()):
ax[i].text(pos[tick], medians[tick] + 0.03, nobs[tick],
horizontalalignment='center', size='small', color='k', weight='semibold')
sns.boxplot(data = dataframe,
x= dataframe[column],
y='saleprice',
ax=ax[i])
ax[i].set_title(list_of_titles[i],fontdict={'fontsize': 15})
ax[i].xaxis.set_visible(True);
Subplot works fine. My numbers of observations are plotted as well.
However, the number of observations can only be plotted on 6 categories. Here is an example:
Only shows n = # for 6 categories.
Only shows n = # for 6 categories.

