Seaborn Statistical Visualization
Overview
Seaborn is a Python visualization library for creating publication-quality statistical graphics. Use this skill for dataset-oriented plotting, multivariate analysis, automatic statistical estimation, and complex multi-panel figures with minimal code.
When to Use This Skill
Use seaborn for quick, attractive statistical graphics straight from a pandas DataFrame: distributions, relationships, categorical comparisons, correlation heatmaps, and faceted small multiples.
Does NOT Trigger
| Scenario |
Use Instead |
| Interactive chart with hover, zoom, or an HTML dashboard |
alterlab-plotly |
| Exact journal/manuscript styling (column widths, point fonts, CMYK, vector export) |
alterlab-scientific-viz |
| Low-level control of individual artists or layouts beyond FacetGrid/PairGrid |
alterlab-matplotlib (seaborn axes-level plots accept ax= for this) |
| A full exploratory-data-analysis report on a data file (structure, quality, summary statistics) |
alterlab-eda |
| Choosing and running the statistical test behind a comparison |
alterlab-statistical-analysis |
Hand-off rule. When the request matches a row above, open your answer by naming that skill by its exact id (for example alterlab-plotly) and saying in one line why it fits better, then stop applying this skill's procedure. Name it even when you also need to ask for missing input. If only part of the request is out of scope, name the skill for that part and do only the in-scope part. A brief general pointer is fine; the named skill does the work.
Design Philosophy
- Dataset-oriented — work directly with DataFrames and named variables, not abstract coordinates.
- Semantic mapping — automatically translate data values into visual properties (color, size, style).
- Statistical awareness — built-in aggregation, error estimation, and confidence intervals.
- Aesthetic defaults — publication-ready themes and palettes out of the box.
- Matplotlib integration — full compatibility with matplotlib customization when needed.
Quick Start
Run scripts without installing anything: uv run --python ">=3.11" --with seaborn python plot.py resolves seaborn (with pandas and matplotlib) per call, with no virtualenv; uv pip install fails outside one.
Examples target seaborn ≥ 0.13 (verified on 0.13.2, still the current release in September 2026). Two API points that bite on this version: pass palette= only together with hue= (palette-without-hue is deprecated and slated for removal in v0.14), and style error bars via err_kws={...} rather than the deprecated errcolor/errwidth/scale/join keywords (slated for removal in v0.15).
With matplotlib 3.11 every plotting function still works, but boxplot (and catplot(kind="box")) emits a vert MatplotlibDeprecationWarning and heatmap a set_bad PendingDeprecationWarning. Both come from seaborn's internals and are harmless for now; matplotlib 3.13 is scheduled to remove vert, so pin matplotlib<3.13 in environments that depend on sns.boxplot until a seaborn release addresses it.
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
df = sns.load_dataset('tips')
sns.scatterplot(data=df, x='total_bill', y='tip', hue='day')
plt.show()
Core Workflow
- Shape the data as long-form ("tidy") — one column per variable, one row per observation. This works with every seaborn function. Reshape wide data with
df.melt(...). See references/data_palettes_theming.md.
- Pick the plot category for your variable types (see routing below).
- Encode extra dimensions with
hue, size, style semantic mappings.
- Choose axes-level vs figure-level: axes-level (
scatterplot, boxplot, heatmap, …) plug into custom matplotlib layouts via ax=; figure-level (relplot, displot, catplot, lmplot, …) own the whole figure and facet via col/row.
- Theme and save with
set_theme/set_context and savefig(dpi=300, bbox_inches='tight') (PDF for vector).
Plot Category Routing
Choose the category, then see references/plotting_functions.md for parameters and code for each.
| Goal |
Category |
Key functions |
| How variables relate |
Relational |
scatterplot, lineplot, relplot |
| Spread / shape / density |
Distribution |
histplot, kdeplot, ecdfplot, displot, jointplot, pairplot |
| Compare across categories |
Categorical |
stripplot, swarmplot, boxplot, violinplot, barplot, pointplot, countplot, catplot |
| Linear relationships / residuals |
Regression |
regplot, lmplot, residplot |
| Matrices / correlations |
Matrix |
heatmap, clustermap |
| Custom multi-panel grids |
Grids |
FacetGrid, PairGrid, JointGrid |
The modern declarative seaborn.objects interface (ggplot2-like, composable) is best for complex layered or programmatic plots — see references/objects_interface.md.
Color and Theming (essentials)
- Qualitative palettes for categories (
"colorblind", "deep", "muted"); sequential for ordered data ("rocket", "viridis"); diverging for centered data ("vlag", "coolwarm", with center=0).
set_theme(style=..., context=..., palette=...); styles whitegrid/ticks/…; contexts paper→talk→poster scale element sizes.
Full palette and theming reference: references/data_palettes_theming.md.
Best Practices (essentials)
- Plot from named DataFrame columns (preserves axis labels); use figure-level functions for faceting; encode extra dimensions with
hue/size/style.
- Know what each function estimates:
lineplot/barplot auto-compute mean + CI — override with errorbar= and estimator=.
- Combine with matplotlib (
ax.set(...), axhline, tight_layout) for fine-tuning; save at dpi=300, and PDF for publications.
Full best-practices, common patterns, and troubleshooting (legend placement, overlapping labels, figure sizing, palette distinctness, KDE bandwidth): references/best_practices_and_troubleshooting.md.
Reference Index
references/plotting_functions.md — every plot category with parameters and code (relational, distribution, categorical, regression, matrix, multi-plot grids, figure-vs-axes-level).
references/data_palettes_theming.md — long/wide data structure, color palettes (qualitative/sequential/diverging/custom), and theming (set_theme, styles, contexts).
references/best_practices_and_troubleshooting.md — best practices, common patterns (EDA, publication figures, multi-panel, time series), and troubleshooting.
references/function_reference.md — comprehensive function signatures, parameters, and examples.
references/objects_interface.md — detailed guide to the modern seaborn.objects API.
references/examples.md — scenario-based worked examples and code patterns.
1---2name: alterlab-seaborn3description: Builds statistical plots with the seaborn Python library and pandas DataFrame integration, on attractive matplotlib-based defaults. Use for quick exploration of distributions, relationships, and categorical comparisons — box plots, violin plots, swarm/strip plots, KDE/histograms, pair plots, joint plots, regression plots, correlation heatmaps, and faceted small multiples (relplot/displot/catplot/lmplot). For interactive/hover/zoom charts defer to alterlab-plotly; for exact journal/manuscript styling (column widths, point fonts, CMYK, vector export) defer to alterlab-scientific-viz; for low-level custom matplotlib figures defer to alterlab-matplotlib (seaborn integrates with it for fine-tuning). Part of the AlterLab Academic Skills suite.4license: MIT5allowed-tools: Read Write Edit Bash(python:*) Bash(uv run:*)6compatibility: Requires seaborn >= 0.13 (current 0.13.2 as of 2026-09) and pandas — no install step, run scripts as uv run --python ">=3.11" --with seaborn python plot.py (seaborn brings pandas and matplotlib); verified on matplotlib 3.11 and pandas 3.0; no API key or external service needed7metadata:8 source: https://skillmd.com/skills/alterlab-ieu/alterlab-seaborn9 skill-author: AlterLab10 version: "1.1.0"11 last_updated: "2026-09-23"12---1314# Seaborn Statistical Visualization1516## Overview1718Seaborn is a Python visualization library for creating publication-quality statistical graphics. Use this skill for dataset-oriented plotting, multivariate analysis, automatic statistical estimation, and complex multi-panel figures with minimal code.1920## When to Use This Skill2122Use seaborn for quick, attractive statistical graphics straight from a pandas DataFrame: distributions, relationships, categorical comparisons, correlation heatmaps, and faceted small multiples.2324### Does NOT Trigger2526| Scenario | Use Instead |27|----------|-------------|28| Interactive chart with hover, zoom, or an HTML dashboard | `alterlab-plotly` |29| Exact journal/manuscript styling (column widths, point fonts, CMYK, vector export) | `alterlab-scientific-viz` |30| Low-level control of individual artists or layouts beyond FacetGrid/PairGrid | `alterlab-matplotlib` (seaborn axes-level plots accept `ax=` for this) |31| A full exploratory-data-analysis report on a data file (structure, quality, summary statistics) | `alterlab-eda` |32| Choosing and running the statistical test behind a comparison | `alterlab-statistical-analysis` |3334**Hand-off rule.** When the request matches a row above, open your answer by naming that skill by its exact id (for example `alterlab-plotly`) and saying in one line why it fits better, then stop applying this skill's procedure. Name it even when you also need to ask for missing input. If only part of the request is out of scope, name the skill for that part and do only the in-scope part. A brief general pointer is fine; the named skill does the work.3536## Design Philosophy37381. **Dataset-oriented** — work directly with DataFrames and named variables, not abstract coordinates.392. **Semantic mapping** — automatically translate data values into visual properties (color, size, style).403. **Statistical awareness** — built-in aggregation, error estimation, and confidence intervals.414. **Aesthetic defaults** — publication-ready themes and palettes out of the box.425. **Matplotlib integration** — full compatibility with matplotlib customization when needed.4344## Quick Start4546Run scripts without installing anything: `uv run --python ">=3.11" --with seaborn python plot.py` resolves seaborn (with pandas and matplotlib) per call, with no virtualenv; `uv pip install` fails outside one.4748Examples target **seaborn ≥ 0.13** (verified on 0.13.2, still the current release in September 2026). Two API points that bite on this version: pass `palette=` only together with `hue=` (palette-without-hue is deprecated and slated for removal in v0.14), and style error bars via `err_kws={...}` rather than the deprecated `errcolor`/`errwidth`/`scale`/`join` keywords (slated for removal in v0.15).4950With matplotlib 3.11 every plotting function still works, but `boxplot` (and `catplot(kind="box")`) emits a `vert` MatplotlibDeprecationWarning and `heatmap` a `set_bad` PendingDeprecationWarning. Both come from seaborn's internals and are harmless for now; matplotlib 3.13 is scheduled to remove `vert`, so pin `matplotlib<3.13` in environments that depend on `sns.boxplot` until a seaborn release addresses it.5152```python53import seaborn as sns54import matplotlib.pyplot as plt55import pandas as pd5657df = sns.load_dataset('tips')58sns.scatterplot(data=df, x='total_bill', y='tip', hue='day')59plt.show()60```6162## Core Workflow63641. **Shape the data** as long-form ("tidy") — one column per variable, one row per observation. This works with every seaborn function. Reshape wide data with `df.melt(...)`. See `references/data_palettes_theming.md`.652. **Pick the plot category** for your variable types (see routing below).663. **Encode extra dimensions** with `hue`, `size`, `style` semantic mappings.674. **Choose axes-level vs figure-level**: axes-level (`scatterplot`, `boxplot`, `heatmap`, …) plug into custom matplotlib layouts via `ax=`; figure-level (`relplot`, `displot`, `catplot`, `lmplot`, …) own the whole figure and facet via `col`/`row`.685. **Theme and save** with `set_theme`/`set_context` and `savefig(dpi=300, bbox_inches='tight')` (PDF for vector).6970## Plot Category Routing7172Choose the category, then see `references/plotting_functions.md` for parameters and code for each.7374| Goal | Category | Key functions |75|------|----------|---------------|76| How variables relate | Relational | `scatterplot`, `lineplot`, `relplot` |77| Spread / shape / density | Distribution | `histplot`, `kdeplot`, `ecdfplot`, `displot`, `jointplot`, `pairplot` |78| Compare across categories | Categorical | `stripplot`, `swarmplot`, `boxplot`, `violinplot`, `barplot`, `pointplot`, `countplot`, `catplot` |79| Linear relationships / residuals | Regression | `regplot`, `lmplot`, `residplot` |80| Matrices / correlations | Matrix | `heatmap`, `clustermap` |81| Custom multi-panel grids | Grids | `FacetGrid`, `PairGrid`, `JointGrid` |8283The modern declarative `seaborn.objects` interface (ggplot2-like, composable) is best for complex layered or programmatic plots — see `references/objects_interface.md`.8485## Color and Theming (essentials)8687- **Qualitative** palettes for categories (`"colorblind"`, `"deep"`, `"muted"`); **sequential** for ordered data (`"rocket"`, `"viridis"`); **diverging** for centered data (`"vlag"`, `"coolwarm"`, with `center=0`).88- `set_theme(style=..., context=..., palette=...)`; styles `whitegrid`/`ticks`/…; contexts `paper`→`talk`→`poster` scale element sizes.8990Full palette and theming reference: `references/data_palettes_theming.md`.9192## Best Practices (essentials)9394- Plot from named DataFrame columns (preserves axis labels); use figure-level functions for faceting; encode extra dimensions with `hue`/`size`/`style`.95- Know what each function estimates: `lineplot`/`barplot` auto-compute mean + CI — override with `errorbar=` and `estimator=`.96- Combine with matplotlib (`ax.set(...)`, `axhline`, `tight_layout`) for fine-tuning; save at `dpi=300`, and PDF for publications.9798Full best-practices, common patterns, and troubleshooting (legend placement, overlapping labels, figure sizing, palette distinctness, KDE bandwidth): `references/best_practices_and_troubleshooting.md`.99100## Reference Index101102- **`references/plotting_functions.md`** — every plot category with parameters and code (relational, distribution, categorical, regression, matrix, multi-plot grids, figure-vs-axes-level).103- **`references/data_palettes_theming.md`** — long/wide data structure, color palettes (qualitative/sequential/diverging/custom), and theming (`set_theme`, styles, contexts).104- **`references/best_practices_and_troubleshooting.md`** — best practices, common patterns (EDA, publication figures, multi-panel, time series), and troubleshooting.105- **`references/function_reference.md`** — comprehensive function signatures, parameters, and examples.106- **`references/objects_interface.md`** — detailed guide to the modern `seaborn.objects` API.107- **`references/examples.md`** — scenario-based worked examples and code patterns.