sns.histplot shows the distribution of a variable, with the grouping and stacking that make comparing subgroups effortless — and smarter default bin choices than raw Matplotlib.
Basic & grouped
sns.histplot(data=penguins, x="flipper_length_mm", bins=20)sns.histplot(data=penguins, x="flipper_length_mm",hue="species", # a coloured histogram per speciesmultiple="stack") # stack, dodge, layer, or fill
The multiple= modes
When you group with hue, multiple= decides how the groups are arranged: "layer" (overlap, default), "stack", "dodge" (side by side), or "fill" (100% proportions).
Key takeaways
- 01sns.histplot shows a variable's distribution with smart default binning.
- 02hue splits the histogram by group; multiple= sets layer/stack/dodge/fill.
- 03kde=True overlays a smooth density curve.
- 04Set bins= or binwidth= to control the bins.
