seaborn
is a high-level api for matplotlib
, and pandas
uses matplotlib
as the default plotting backend.
- From
seaborn v0.11.2
, sns.distplot
is deprecated, and, as per the Warning in the documentation, it is not recommended to directly use FacetGrid
.
sns.distplot
is replaced by the axes-level function sns.histplot
, and the figure-level function sns.displot
.
- Also see seaborn histplot and displot output doesn't match
- It is easy to produce a plot, but not necessarily to produce the correct plot, unless you are aware of the different parameter defaults for each api.
- Note the difference between
common_bins
as True
and Fales
.
- Tested in
python 3.10
, pandas 1.4.2
, matplotlib 3.5.1
, seaborn 0.11.2
common_bins=False
import seaborn as sns
# plot
g = sns.displot(data=df, x='similarity', col='group', col_wrap=2, common_bins=False, height=4)

common_bins=True
(4)
sns.displot
, and pandas.DataFrame.plot
with kind='hist'
and bins=4
produce the same plot.
g = sns.displot(data=df, x='similarity', col='group', col_wrap=2, common_bins=True, bins=4, height=4)

# reshape the dataframe to a wide format
dfp = df.pivot(columns='group', values='similarity')
axes = dfp.plot(kind='hist', subplots=True, layout=(2, 2), figsize=(9, 9), ec='k', bins=4, sharey=True)
