Explore a univariate distribution
Inspect the shape, spread, and modality of one numeric variable.
Seaborn · Function
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.
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.
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*)| Name | Type | Description |
|---|---|---|
data | DataFrame, array, or mapping | Input data structure, such as a long-form DataFrame, vector, or mapping. |
x | vector or key in data | Input variable for the univariate density estimate. |
y | vector or key in data | Input variable for the y axis of a bivariate density estimate. |
hue | vector or key in data | Semantic variable that determines subsets and color mapping. |
weights | vector or key in data | Weights applied to observations when estimating the density. |
palette | palette name, list, or mapping | Color palette used for hue levels. |
hue_order | list of strings | Order for displaying hue levels. |
hue_norm | Normalize object or tuple | Normalization for mapping hue values to colors. |
color | matplotlib color | Single color for all density elements. |
fill | bool | Whether to fill the area or bivariate contours. |
multiple | {layer, stack, fill, dodge} | Arrangement mode for multiple densities. |
common_norm | bool | Whether grouped densities share normalization. |
Returns the matplotlib Axes object with the plot drawn on it.
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.
Inspect the shape, spread, and modality of one numeric variable.
Compare a numeric measurement across categories.
Inspect concentration and relationship structure for two numeric variables.
Produce publication-style density graphics with controlled contours, fills, or clipping.
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.
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.
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.
histplotecdfplotrugplotdisplotjointplotpairplot