I've been struggling with visualizing subplots column wrapping in Seaborn histogram plots (kdeplot, histplot). Tried various things including fig, ax
& enumerate(zip(df.columns, ax.flatten())
.
Here's the dataset
for col in df.columns:
plt.figure(figsize = (3,3))
sns.histplot(df, x = col, kde = True, bins = 40, hue = 'Dataset', fill = True)
plt.show();
How can the plots be done with other seaborn plots or plots with facet wrap functionality?
seaborn.displot
withkind='hist'
can be used to create subplots / facets, wherecol_wrap
specifies the number of columns.nrows
andncols
when using axes-level plots.'Female'
and'Male'
should be shown separately, because gender statistics are often different, so presenting them together can skew the impression of the data.'Gender'
produces the best display option.python 3.11.3
,pandas 2.0.1
,matplotlib 3.7.1
,seaborn 0.12.2
common_bins=False
means the bins of the two hue groups don't align. However, setting it toTrue
causessharex=False
to be ignored, so all of the x-axis limits will be 0 - 2000, as can be seen in this plot.col_wrap
can't be used ifrow
is also in use.'Gender'
.common_bins=True
to be used.df
have significant outliers. Removing them will improve the histogram visualization.