Seaborn Cheat Sheet
Seaborn statistical visualization cheat sheet covering distribution, relational, and categorical plots plus heatmaps and figure-level facet grids.
Distribution & Relational Plots
Explore relationships and distributions.
import seaborn as snsimport matplotlib.pyplot as pltsns.set_theme(style="whitegrid")sns.scatterplot(data=df, x="total_bill", y="tip", hue="time", size="size")sns.lineplot(data=df, x="date", y="value", hue="category")sns.histplot(data=df, x="age", bins=30, kde=True)plt.show()
Categorical Plots
Compare a numeric variable across categories.
sns.boxplot(data=df, x="day", y="total_bill", hue="sex")sns.violinplot(data=df, x="day", y="total_bill")sns.barplot(data=df, x="day", y="total_bill", estimator="mean", errorbar="ci")sns.countplot(data=df, x="day")
Correlation & Pairwise Plots
Visualize correlations across many variables.
sns.pairplot(df, hue="species") # matrix of pairwise plotscorr = df.corr(numeric_only=True)sns.heatmap(corr, annot=True, cmap="coolwarm", vmin=-1, vmax=1)sns.regplot(data=df, x="x", y="y") # scatter + regression line
Figure-Level Functions
Wrappers that support faceting.
- relplot- figure-level wrapper for scatterplot/lineplot
- displot- figure-level wrapper for histplot/kdeplot/ecdfplot
- catplot- figure-level wrapper for box/violin/bar/strip plots
- jointplot- bivariate plot with marginal distributions
- FacetGrid- manually facet data across rows/columns
- sns.set_palette- set a named or custom color palette
Objects Interface (sns.objects)
Compose plots declaratively with the newer grammar-of-graphics API.
import seaborn.objects as so( so.Plot(df, x="total_bill", y="tip", color="time") .add(so.Dot(alpha=.6), so.Jitter()) .add(so.Line(), so.PolyFit(order=1)) .scale(color="flare") .facet(col="day", wrap=2) .layout(size=(8, 6)) .save("plot.png", dpi=200))
Bootstrapped Confidence Intervals
Control the estimator and resampling used by bar/line/point plots.
sns.lineplot( data=df, x="timepoint", y="signal", estimator="median", errorbar=("ci", 90), n_boot=2000, seed=42,)# custom errorbar function: return (lower, upper)def iqr_band(x): return (x.quantile(0.25), x.quantile(0.75))sns.barplot(data=df, x="day", y="total_bill", errorbar=iqr_band)
Custom Functions on a FacetGrid
Map arbitrary plotting functions across facets for full control.
g = sns.FacetGrid(df, col="region", row="segment", margin_titles=True, height=3)def annotated_scatter(x, y, **kwargs): ax = plt.gca() ax.scatter(x, y, **kwargs) r = x.corr(y) ax.annotate(f"r={r:.2f}", xy=(.05, .9), xycoords="axes fraction")g.map(annotated_scatter, "spend", "revenue", alpha=.5)g.add_legend()g.set_axis_labels("Spend ($)", "Revenue ($)")g.tight_layout()
Clustermap with Dendrograms
Hierarchically cluster rows/columns and render a heatmap with linkage trees.
from scipy.spatial.distance import pdistfrom scipy.cluster.hierarchy import linkageg = sns.clustermap( df.corr(numeric_only=True), method="average", metric="euclidean", cmap="vlag", center=0, row_cluster=True, col_cluster=True, dendrogram_ratio=(.15, .15), cbar_pos=(0.02, 0.8, 0.03, 0.18),)g.ax_heatmap.set_xticklabels(g.ax_heatmap.get_xticklabels(), rotation=45, ha="right")
Theming & Context Internals
Fine-grained controls beyond set_theme() for publication-quality output.
- sns.plotting_context- context manager that scales font/line sizes (paper, notebook, talk, poster)
- sns.axes_style- context manager for temporarily overriding grid/spine style within a `with` block
- despine(trim=True)- removes top/right spines and trims remaining spines to the data range
- mpl.rcParams via sns.set_theme(rc=...)- pass a dict of raw matplotlib rcParams alongside the seaborn theme
- move_legend- reposition or restyle a plot's legend after creation without recomputing it
- color_palette(as_cmap=True)- return a seaborn palette as a matplotlib Colormap for use in imshow/heatmap
- husl / hls color spaces- perceptually uniform palettes generated via `sns.husl_palette` / `sns.hls_palette`
Prefer the figure-level functions (relplot, catplot, displot) over their axes-level counterparts when you need faceting via row=/col= — they return a FacetGrid that handles legends and layout automatically.