Alterlab seaborn

From AlterLab-IEU/AlterLab-Academic-Skills · View interactive version

Alterlab seaborn is an AI agent skill from the GitHub repository AlterLab-IEU/AlterLab-Academic-Skills. 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 p

How to use this skill

Skill file

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

  1. Dataset-oriented — work directly with DataFrames and named variables, not abstract coordinates.
  2. Semantic mapping — automatically translate data values into visual properties (color, size, style).
  3. Statistical awareness — built-in aggregation, error estimation, and confidence intervals.
  4. Aesthetic defaults — publication-ready themes and palettes out of the box.
  5. 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

  1. 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.
  2. Pick the plot category for your variable types (see routing below).
  3. Encode extra dimensions with hue, size, style semantic mappings.
  4. 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.
  5. 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)

Full palette and theming reference: references/data_palettes_theming.md.

Best Practices (essentials)

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

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.