Statistical data visualization library for Python built on matplotlib
—
Visualize statistical relationships between variables using scatter plots, line plots, and regression analysis. These functions support semantic mapping with color, size, and style to reveal patterns across different groups in your data.
Create multi-panel figures with relational plots across subsets of data.
def relplot(
data,
*,
x=None,
y=None,
hue=None,
size=None,
style=None,
units=None,
row=None,
col=None,
col_wrap=None,
row_order=None,
col_order=None,
palette=None,
hue_order=None,
hue_norm=None,
sizes=None,
size_order=None,
size_norm=None,
markers=None,
dashes=None,
style_order=None,
legend="auto",
kind="scatter",
height=5,
aspect=1,
facet_kws=None,
**kwargs
):
"""
Figure-level interface for drawing relational 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
- size: str, grouping variable for size mapping
- style: str, grouping variable for style mapping
- row, col: str, variables for faceting into subplots
- kind: str, either "scatter" or "line"
- height: float, height of each facet in inches
- aspect: float, aspect ratio of each facet
Returns:
FacetGrid object
"""Draw scatter plots with semantic groupings for exploring relationships between continuous variables.
def scatterplot(
data=None,
*,
x=None,
y=None,
hue=None,
size=None,
style=None,
palette=None,
hue_order=None,
hue_norm=None,
sizes=None,
size_order=None,
size_norm=None,
markers=True,
style_order=None,
legend="auto",
ax=None,
**kwargs
):
"""
Draw a scatter plot with possibility of several semantic groupings.
Parameters:
- data: DataFrame, dict, or array of data
- x, y: str or array-like, input data variables
- hue: str, grouping variable for color mapping
- size: str, grouping variable for point sizes
- style: str, grouping variable for point markers
- palette: str or list, colors to use for hue levels
- sizes: tuple or dict, size range or mapping for size variable
- markers: bool or list, marker styles for style levels
- ax: matplotlib Axes, axes object to draw plot onto
Returns:
matplotlib Axes object
"""Draw line plots with semantic groupings for time series and ordered data visualization.
def lineplot(
data=None,
*,
x=None,
y=None,
hue=None,
size=None,
style=None,
units=None,
weights=None,
palette=None,
hue_order=None,
hue_norm=None,
sizes=None,
size_order=None,
size_norm=None,
dashes=True,
markers=None,
style_order=None,
estimator="mean",
errorbar=("ci", 95),
n_boot=1000,
seed=None,
orient="x",
sort=True,
err_style="band",
err_kws=None,
legend="auto",
ci="deprecated",
ax=None,
**kwargs
):
"""
Draw a line plot with possibility of several semantic groupings.
Parameters:
- data: DataFrame, dict, or array of data
- x, y: str or array-like, input data variables
- hue: str, grouping variable for color mapping
- size: str, grouping variable for line width
- style: str, grouping variable for line style
- units: str, grouping variable for individual line segments
- weights: str, grouping variable for observation weights
- estimator: str or callable, statistical function for aggregation
- errorbar: str or tuple, error bar representation method
- sort: bool, whether to sort x variable
- err_style: str, "band" or "bars" for error representation
Returns:
matplotlib Axes object
"""Visualize linear relationships with regression lines and confidence intervals.
def regplot(
data=None,
*,
x=None,
y=None,
x_estimator=None,
x_bins=None,
x_ci="ci",
scatter=True,
fit_reg=True,
ci=95,
n_boot=1000,
units=None,
seed=None,
order=1,
logistic=False,
lowess=False,
robust=False,
logx=False,
x_partial=None,
y_partial=None,
truncate=True,
dropna=True,
x_jitter=None,
y_jitter=None,
label=None,
color=None,
marker="o",
scatter_kws=None,
line_kws=None,
ax=None,
**kwargs
):
"""
Plot data and a linear regression model fit.
Parameters:
- data: DataFrame, dict, or array of data
- x, y: str or array-like, input data variables
- x_estimator: callable, function for binning x variable
- scatter: bool, whether to draw scatter plot points
- fit_reg: bool, whether to fit regression line
- ci: int or None, confidence interval size
- order: int, polynomial order for regression
- logistic: bool, fit logistic regression
- lowess: bool, fit lowess smoother
- robust: bool, fit robust regression
- scatter_kws: dict, keyword arguments for scatter plot
- line_kws: dict, keyword arguments for regression line
Returns:
matplotlib Axes object
"""Create regression plots across multiple subsets of data.
def lmplot(
data,
*,
x=None,
y=None,
hue=None,
col=None,
row=None,
palette=None,
col_wrap=None,
height=5,
aspect=1,
markers="o",
sharex=None,
sharey=None,
hue_order=None,
col_order=None,
row_order=None,
legend=True,
legend_out=None,
x_estimator=None,
x_bins=None,
x_ci="ci",
scatter=True,
fit_reg=True,
ci=95,
n_boot=1000,
units=None,
seed=None,
order=1,
logistic=False,
lowess=False,
robust=False,
logx=False,
x_partial=None,
y_partial=None,
truncate=True,
x_jitter=None,
y_jitter=None,
scatter_kws=None,
line_kws=None,
facet_kws=None,
**kwargs
):
"""
Plot data and regression model fits across a FacetGrid.
Parameters:
- data: DataFrame
- x, y: str, names of variables in data
- hue: str, grouping variable for color mapping
- col, row: str, variables for faceting into subplots
- height: float, height of each facet in inches
- aspect: float, aspect ratio of each facet
- markers: str or list, marker styles for hue levels
- All regplot parameters are also accepted
Returns:
FacetGrid object
"""Plot residuals of linear regression for model diagnostics.
def residplot(
data=None,
*,
x=None,
y=None,
x_partial=None,
y_partial=None,
lowess=False,
order=1,
robust=False,
dropna=True,
label=None,
color=None,
scatter_kws=None,
line_kws=None,
ax=None,
**kwargs
):
"""
Plot the residuals of a linear regression.
Parameters:
- data: DataFrame, dict, or array of data
- x, y: str or array-like, input data variables
- x_partial, y_partial: str, variables to partial out
- lowess: bool, fit lowess smoother to residuals
- order: int, polynomial order for regression
- robust: bool, use robust regression
- scatter_kws: dict, keyword arguments for scatter plot
- line_kws: dict, keyword arguments for reference line
Returns:
matplotlib Axes object
"""import seaborn as sns
import matplotlib.pyplot as plt
# Load dataset
tips = sns.load_dataset("tips")
# Basic scatter plot
sns.scatterplot(data=tips, x="total_bill", y="tip")
plt.show()# Scatter plot with color grouping
sns.scatterplot(data=tips, x="total_bill", y="tip", hue="time", style="smoker")
plt.show()# Create subplots by day of week
sns.relplot(
data=tips,
x="total_bill", y="tip",
col="day", hue="time",
kind="scatter"
)
plt.show()# Time series with error bands
flights = sns.load_dataset("flights")
sns.lineplot(data=flights, x="year", y="passengers")
plt.show()# Linear regression with confidence interval
sns.regplot(data=tips, x="total_bill", y="tip")
plt.show()Install with Tessl CLI
npx tessl i tessl/pypi-seaborn