Statistical data visualization library for Python built on matplotlib
—
Analyze and visualize statistical distributions using histograms, kernel density estimation, empirical cumulative distribution functions, and rug plots. These functions support both univariate and bivariate distribution analysis with flexible styling and statistical options.
Create multi-panel figures with distribution plots across subsets of data.
def displot(
data,
*,
x=None,
y=None,
hue=None,
row=None,
col=None,
weights=None,
kind="hist",
rug=False,
rug_kws=None,
log_scale=None,
legend=True,
palette=None,
hue_order=None,
hue_norm=None,
color=None,
col_wrap=None,
row_order=None,
col_order=None,
height=5,
aspect=1,
facet_kws=None,
**kwargs
):
"""
Figure-level interface for drawing distribution plots onto a FacetGrid.
Parameters:
- data: DataFrame, dict, or array of data
- x, y: str, names of variables in data
- hue: str, grouping variable for color mapping
- row, col: str, variables for faceting into subplots
- kind: str, plot type ("hist", "kde", "ecdf")
- rug: bool, add marginal rug plot
- weights: str, variable for observation weights
- height: float, height of each facet in inches
- aspect: float, aspect ratio of each facet
Returns:
FacetGrid object
"""Plot univariate or bivariate histograms to show data distributions.
def histplot(
data=None,
*,
x=None,
y=None,
hue=None,
weights=None,
stat="count",
bins="auto",
binwidth=None,
binrange=None,
discrete=None,
cumulative=False,
common_bins=True,
common_norm=True,
multiple="layer",
element="bars",
fill=True,
shrink=1,
kde=False,
kde_kws=None,
line_kws=None,
thresh=0,
pthresh=None,
pmax=None,
cbar=False,
cbar_ax=None,
cbar_kws=None,
palette=None,
hue_order=None,
hue_norm=None,
color=None,
log_scale=None,
legend=True,
ax=None,
**kwargs
):
"""
Plot univariate or bivariate histograms to show distributions of datasets.
Parameters:
- data: DataFrame, dict, or array of data
- x, y: str or array-like, input data variables
- hue: str, grouping variable for color mapping
- stat: str, statistic to compute ("count", "frequency", "probability", "proportion", "percent", "density")
- bins: int, str, or sequence, binning specification
- binwidth: float, width of bins
- cumulative: bool, compute cumulative statistic
- multiple: str, approach for multiple hue levels ("layer", "dodge", "stack", "fill")
- element: str, visual representation ("bars", "step", "poly")
- kde: bool, overlay kernel density estimate
Returns:
matplotlib Axes object
"""Plot univariate or bivariate distributions using kernel density estimation.
def 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
):
"""
Plot univariate or bivariate distributions using kernel density estimation.
Parameters:
- data: DataFrame, dict, or array of data
- x, y: str or array-like, input data variables
- hue: str, grouping variable for color mapping
- fill: bool, fill area under univariate curves
- bw_method: str or scalar, bandwidth estimation method
- bw_adjust: float, bandwidth scaling factor
- levels: int or sequence, contour levels for bivariate plots
- thresh: float, density threshold for contours
- gridsize: int, evaluation grid size
- cut: float, distance to extend beyond data extremes
- clip: tuple, data range to clip density
Returns:
matplotlib Axes object
"""Plot empirical cumulative distribution functions (ECDFs).
def ecdfplot(
data=None,
*,
x=None,
y=None,
hue=None,
weights=None,
stat="proportion",
complementary=False,
palette=None,
hue_order=None,
hue_norm=None,
log_scale=None,
legend=True,
ax=None,
**kwargs
):
"""
Plot empirical cumulative distribution functions.
Parameters:
- data: DataFrame, dict, or array of data
- x, y: str or array-like, input data variables
- hue: str, grouping variable for color mapping
- stat: str, statistic to compute ("proportion" or "count")
- complementary: bool, plot complementary CDF (1 - CDF)
- weights: str or array-like, observation weights
Returns:
matplotlib Axes object
"""Plot marginal distributions as tick marks along axes.
def rugplot(
data=None,
*,
x=None,
y=None,
hue=None,
height=0.025,
expand_margins=True,
palette=None,
hue_order=None,
hue_norm=None,
legend=True,
ax=None,
**kwargs
):
"""
Plot marginal distributions by drawing ticks along the x and y axes.
Parameters:
- data: DataFrame, dict, or array of data
- x, y: str or array-like, input data variables
- hue: str, grouping variable for color mapping
- height: float, height of ticks as proportion of total
- expand_margins: bool, expand axis margins to fit ticks
Returns:
matplotlib Axes object
"""Legacy function for flexible univariate distribution plotting (deprecated in favor of histplot/kdeplot).
def distplot(
a,
bins=None,
hist=True,
kde=True,
rug=False,
fit=None,
hist_kws=None,
kde_kws=None,
rug_kws=None,
fit_kws=None,
color=None,
vertical=False,
norm_hist=False,
axlabel=None,
label=None,
ax=None,
x=None
):
"""
DEPRECATED - Flexibly plot a univariate distribution of observations.
Note: This function is deprecated. Use histplot() and/or kdeplot() instead.
Parameters:
- a: array-like, observed data
- bins: int or sequence, histogram bins
- hist: bool, plot histogram
- kde: bool, plot kernel density estimate
- rug: bool, plot rug plot
- fit: distribution, fit parametric distribution
Returns:
matplotlib Axes object
"""import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
# Basic histogram
sns.histplot(data=tips, x="total_bill")
plt.show()# Histogram with hue grouping
sns.histplot(data=tips, x="total_bill", hue="smoker", multiple="stack")
plt.show()# KDE plot with fill
sns.kdeplot(data=tips, x="total_bill", fill=True)
plt.show()# 2D histogram
sns.histplot(data=tips, x="total_bill", y="tip")
plt.show()
# 2D KDE with contours
sns.kdeplot(data=tips, x="total_bill", y="tip")
plt.show()# Empirical cumulative distribution
sns.ecdfplot(data=tips, x="total_bill", hue="smoker")
plt.show()# Create subplots by time
sns.displot(
data=tips,
x="total_bill", hue="smoker",
col="time", kind="hist"
)
plt.show()# Histogram with KDE overlay and rug plot
sns.histplot(data=tips, x="total_bill", kde=True)
sns.rugplot(data=tips, x="total_bill")
plt.show()Install with Tessl CLI
npx tessl i tessl/pypi-seaborn