Seaborn Distribution Plots

How is a variable distributed?

๐Ÿ“Š histplot

sns.histplot(data=df, x="total_bill")
sns.histplot(data=df, x="total_bill", bins=30)
sns.histplot(data=df, x="total_bill", hue="time")                        # overlaid histograms by category
sns.histplot(data=df, x="total_bill", hue="time", multiple="stack")         # stacked instead of overlaid
sns.histplot(data=df, x="total_bill", kde=True)                                # add a KDE curve on top
sns.histplot(data=df, x="total_bill", stat="density")                             # normalize to density instead of count
multiple=Effect (with hue)
"layer" (default)overlapping, semi-transparent
"stack"stacked bars
"dodge"side-by-side bars
"fill"stacked, normalized to 100%

๐ŸŒŠ kdeplot โ€” smoothed density curve

sns.kdeplot(data=df, x="total_bill")
sns.kdeplot(data=df, x="total_bill", hue="time")
sns.kdeplot(data=df, x="total_bill", hue="time", fill=True)         # shaded area under curve
sns.kdeplot(data=df, x="total_bill", y="tip")                          # 2D density (contour plot)

KDE = smoothed histogram. Good for comparing shapes of distributions across groups without bin-width artifacts.

๐Ÿ“ถ ecdfplot โ€” cumulative distribution

sns.ecdfplot(data=df, x="total_bill")
sns.ecdfplot(data=df, x="total_bill", hue="time")

ECDF shows "what % of data is โ‰ค x" โ€” no binning choices needed, often clearer than a histogram for comparing distributions.

๐Ÿ“ rugplot โ€” raw data ticks along an axis

sns.rugplot(data=df, x="total_bill")
sns.histplot(data=df, x="total_bill")
sns.rugplot(data=df, x="total_bill")     # combine: histogram + individual data point ticks

๐ŸŽฏ displot โ€” figure-level wrapper

sns.displot(data=df, x="total_bill", kind="hist")
sns.displot(data=df, x="total_bill", kind="kde")
sns.displot(data=df, x="total_bill", kind="ecdf")
 
sns.displot(data=df, x="total_bill", col="time", kind="hist")      # facet by category

๐Ÿงฎ Choosing which one

QuestionUse
Shape + counts, simplehistplot
Smooth shape comparison across groupskdeplot
โ€What fraction is below Xโ€ecdfplot
Faceted grid of distributionsdisplot

๐Ÿ”— Next

Seaborn Categorical Plots ยท Seaborn Multi-Plot Grids