seaborn histplot and displot output doesn’t match

  • As suggested by mwaskom in a comment, common_bins=False gets the histograms into the same shape, resolving the issues of ignoring bins and sharex, and the density in a faceted plot is scaled by the number of data points in each facet, not the number of facets.
  • The issue with density being split by the number of plots in displot is resolved by using common_norm=False

enter image description here

enter image description here

Plot Code

# displot
fg = sns.displot(data=dfl, x='vals', col="bill_size", kde=True, stat="density", bins=12, height=4,
                 facet_kws={'sharey': False, 'sharex': False}, common_bins=False, common_norm=False)

fg.fig.subplots_adjust(top=0.85)
fg.fig.suptitle('Displot with common_bins & common_norm as False')
plt.show()

# histplot
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4))

sns.histplot(data=dfw.bill_length_mm, kde=True, stat="density", bins=12, ax=ax1)
sns.histplot(data=dfw.bill_depth_mm, kde=True, stat="density", bins=12, ax=ax2)

fig.subplots_adjust(top=0.85)
fig.suptitle('Histplot')

fig.tight_layout()
plt.show()

Leave a Comment