seaborn
seaborn builds statistical graphics on matplotlib with tidy-data APIs - ideal for fast exploratory analysis and polished defaults.
Search across all documentation pages
seaborn builds statistical graphics on matplotlib with tidy-data APIs - ideal for fast exploratory analysis and polished defaults.
Quick-reference recipe card - copy-paste ready.
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
sns.set_theme(style="whitegrid", context="notebook")
df = pd.read_csv("sales.csv", parse_dates=["ordered_at"])
g = sns.relplot(data=df, x="ordered_at", y="revenue", hue="region", kind="line")
g.set_axis_labels("Date", "Revenue ($)")
plt.close()When to reach for this:
col, row)import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
rng = np.random.default_rng(42)
df = pd.DataFrame(
{
"region": np.repeat(["East", "West"], 200),
"segment": np.tile(np.repeat(["SMB", "Enterprise"], 100), 2),
"revenue": rng.normal(150, 40, 400).clip(10),
}
)
sns.set_theme(style="ticks")
fig, axes = plt.subplots(1, 3, figsize=(12, 4))
sns.histplot(data=df, x="revenue", hue="region", kde=True, ax=axes[0])
axes[0].set_title("Distribution")
sns.boxplot(data=df, x="segment", y="revenue", hue="region", ax=axes[1])
axes[1].set_title("By segment")
sns.barplot(
data=df,
x="region",
y="revenue",
estimator="median",
errorbar=("pi", 50),
ax=axes[2],
)
axes[2].set_title("Median with interval")
sns.despine()
fig.tight_layout()
fig.savefig("eda.png", dpi=150, bbox_inches="tight")
plt.close(fig)What this demonstrates:
data= API across three plot typeshistplot with optional KDE overlayboxplot with hue for second categoricalerrorbar tuple instead of deprecated cirelplot, catplot, displot) return FacetGrid.scatterplot, barplot) accept ax= for subplots.| Question | Function |
|---|---|
| Trend over time | lineplot / relplot(kind="line") |
| Category compare | barplot, boxplot, violinplot |
| Distribution | histplot, kdeplot, ecdfplot |
| Relationship | scatterplot, regplot |
import seaborn as sns
# Load sample dataset for teaching
tips = sns.load_dataset("tips") # bundled CSV cache
# Palette accessible to colorblind readers
sns.set_palette("colorblind")melt or fix upstream schema.ci= parameter - removed in seaborn 0.13+. Fix: use errorbar=("ci", 95) or None.plt.close on relplot - figure-level APIs create new figures silently. Fix: capture return value and plt.close().| Alternative | Use When | Don't Use When |
|---|---|---|
pandas .plot | Minimal quick charts | Need statistical CI defaults |
| Plotly express | Interactive exploration | Static print pipeline |
| Altair | Declarative Vega-Lite export | Need matplotlib pixel tweaks |
| matplotlib raw | Full artist control | Repetitive statistical boilerplate |
sns.relplot(data=df, x="x", y="y", col="region", row="segment", kind="scatter")sns.lineplot(data=df, x="t", y="v", errorbar=None)ax=.g = sns.relplot(...)
g.savefig("out.png", dpi=150)colorblind or Set2 for categories.viridis) for continuous values.sns.regplot(data=df, x="ad_spend", y="revenue").to_pandas() for plotting unless using alt/plotly native paths.order = df.groupby("region")["revenue"].median().sort_values().index
sns.barplot(data=df, x="region", y="revenue", order=order)countplot for row counts.Stack versions: This page was written for Python 3.14.0 (stable 3.14, maintenance 3.13), FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.
Reviewed by Chris St. John·Last updated Jul 16, 2026