📊 Seaborn Histogram (Histplot)

Last Updated: 07 Nov 2025


A histogram shows the distribution of a numeric column. It groups values into bins and shows how frequently each range appears.

Hinglish Tip 🗣: Values kis range me kitni baar aate hain — uski picture hoti hai histogram.


Basic Syntax

sns.histplot(data=df, x='numeric_col')
plt.show()

📘 Example Dataset

df = sns.load_dataset('tips')
df.head()

📊 Basic Histogram

sns.histplot(data=df, x='total_bill')
plt.show()

Important Parameters

  • data, x, y Usually we use x for numeric columns. y is optional (for weighted histograms).
  • bins Controls number of bars.
sns.histplot(data=df, x='total_bill', bins=20)
plt.show()
  • kde Add a smooth density curve.
sns.histplot(data=df, x='total_bill', kde=True)
plt.show()
  • hue Different colors for categories.
sns.histplot(data=df, x='total_bill', hue='sex')
plt.show()
  • multiple How bars overlap or stack. Options: 'layer', 'stack', 'dodge', 'fill'
sns.histplot(data=df, x='total_bill', hue='sex', multiple='stack')
plt.show()
  • stat How counts are shown. count, probability, density, percent,
sns.histplot(data=df, x='total_bill', stat='percent')
plt.show()
  • element Style of bars.barsor step
sns.histplot(data=df, x='total_bill', element='step')
plt.show()
  • palette Custom colors.
sns.histplot(data=df, x='total_bill', hue='sex', palette='coolwarm')
plt.show()
  • alpha Transparency.
sns.histplot(data=df, x='total_bill', alpha=0.5)
plt.show()

⭐ Full Example

sns.histplot(
    data=df,
    x='total_bill',
    hue='sex',
    kde=True,
    bins=25,
    alpha=0.6,
    multiple='stack',
    palette='viridis',
    stat='density',
    element='bars'
)
plt.show()

Quick Practice

  1. Use penguins dataset.
  2. Plot a histogram of body_mass_g.
  3. Add KDE.
  4. Add hue for species.
  5. Change bins to 30.
  6. Try multiple='dodge'.