pythonpython-3.xseabornhistogramdisplot

seaborn histplot and displot output doesn't match


import seaborn as sns
import matplotlib.pyplot as plt

# sample data: wide
dfw = sns.load_dataset("penguins", cache=False)[['bill_length_mm', 'bill_depth_mm']].dropna()

# sample data: long
dfl = dfw.melt(var_name='bill_size', value_name='vals')

seaborn.displot

  1. Ignores 'sharex': False, though 'sharey' works
  2. Ignores bins
fg = sns.displot(data=dfl, x='vals', col='bill_size', kde=True, stat='density', bins=12, height=4, facet_kws={'sharey': False, 'sharex': False})
plt.show()

enter image description here

  1. Setting xlim doesn't make a difference
fg = sns.displot(data=dfl, x='vals', col='bill_size', kde=True, stat='density', bins=12, height=4, facet_kws={'sharey': False, 'sharex': False})
axes = fg.axes.ravel()
axes[0].set_xlim(25, 65)
axes[1].set_xlim(13, 26)
plt.show()

enter image description here

seaborn.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.tight_layout()
plt.show()

enter image description here

Update

enter image description here

enter image description here


Solution

  • 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()