Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Seaborn · Function

kdeplot

Plots univariate or bivariate distributions with kernel density estimation. It produces smooth probability-density curves or contours and supports grouping, normalization, bandwidth, and display controls.

How it works

kdeplot estimates a continuous probability density from observations and renders it for one variable or as contours for two variables. Use hue for grouped distributions, while bandwidth, grid, normalization, levels, and clipping options control the estimate and its display.

Syntax

seaborn.kdeplot(*data=None*, ***, *x=None*, *y=None*, *hue=None*, *weights=None*, *palette=None*, *hue_order=None*, *hue_norm=None*, *color=None*, *fill=None*, *multiple='layer'*, *common_norm=True*, *common_grid=False*, *cumulative=False*, *bw_method='scott'*, *bw_adjust=1*, *warn_singular=True*, *log_scale=None*, *levels=10*, *thresh=0.05*, *gridsize=200*, *cut=3*, *clip=None*, *legend=True*, *cbar=False*, *cbar_ax=None*, *cbar_kws=None*, *ax=None*, ***kwargs*)

Parameters

NameTypeDescription
dataDataFrame, array, or mappingInput data structure, such as a long-form DataFrame, vector, or mapping.
xvector or key in dataInput variable for the univariate density estimate.
yvector or key in dataInput variable for the y axis of a bivariate density estimate.
huevector or key in dataSemantic variable that determines subsets and color mapping.
weightsvector or key in dataWeights applied to observations when estimating the density.
palettepalette name, list, or mappingColor palette used for hue levels.
hue_orderlist of stringsOrder for displaying hue levels.
hue_normNormalize object or tupleNormalization for mapping hue values to colors.
colormatplotlib colorSingle color for all density elements.
fillboolWhether to fill the area or bivariate contours.
multiple{layer, stack, fill, dodge}Arrangement mode for multiple densities.
common_normboolWhether grouped densities share normalization.

Returns

Returns the matplotlib Axes object with the plot drawn on it.

Key points

  • Use the function for either one-dimensional density curves or two-dimensional density visualizations.
  • KDE offers a smooth alternative to histogram bins for showing how observations are distributed.
  • The result is a continuous density representation rather than discrete counts.

Example: Compare distributions by category

import matplotlib.pyplot as plt
import seaborn as sns

penguins = sns.load_dataset("penguins")
sns.kdeplot(data=penguins, x="flipper_length_mm", hue="species", fill=True, common_norm=False)
plt.show()

Loads the penguins dataset and draws filled kernel-density curves for flipper length, separated by species.

When to use it

Explore a univariate distribution

Inspect the shape, spread, and modality of one numeric variable.

Compare groups with hue

Compare a numeric measurement across categories.

Visualize a bivariate density

Inspect concentration and relationship structure for two numeric variables.

Customize density rendering

Produce publication-style density graphics with controlled contours, fills, or clipping.

Interview questions

QWhat does kdeplot visualize, and how does its univariate form differ from its bivariate form?

It estimates a continuous probability density from observations, analogous to a histogram but using a smooth curve. With one variable it draws a univariate density; with both x and y, it represents a bivariate density using contours or filled regions.

Follow-up: How would you prevent grouped curves from being normalized together? Set common_norm=False so each subgroup is normalized independently.

QHow do bandwidth controls affect a KDE plot?

bw_method selects the bandwidth rule or value used by the underlying density estimator, and bw_adjust multiplies the resulting bandwidth. Increasing the adjustment produces a smoother estimate; decreasing it produces more detail.

Follow-up: What is a practical risk of a very small bandwidth? It can produce a noisy estimate with artificial modes rather than meaningful distribution structure.

QHow can grouped distributions be compared with kdeplot?

hue maps a categorical variable to separate distributions, while multiple controls how those distributions are displayed, such as layered or stacked arrangements. common_grid determines whether subsets are evaluated on the same grid.

Follow-up: When would common_grid=True help? It makes grouped curves directly comparable because each subset is evaluated at shared coordinate values.

  • histplot
  • ecdfplot
  • rugplot
  • displot
  • jointplot
  • pairplot

Source: seaborn.kdeplot — seaborn 0.13.2 documentation. Checked 2026-10-15.