Seaborn Statistical Visualization
Statistical visualization with pandas integration.
How to use it
- Hit Copy SKILL.md — or use the Claude Code line below to get every file.
- Claude: ⋯ → Download .md, then Customize → Skills → Add → Upload skill.
ChatGPT: make a Project and paste it into Instructions.
Neither? Paste it at the top of a new chat — it works for that chat. - Describe your job in plain words. The AI follows the skill from there.
npx degit K-Dense-AI/scientific-agent-skills/skills/seaborn#main ~/.claude/skills/seabornFor one project only, change the path to .claude/skills/seaborn. This skill also uses function_reference.md, objects_interface.md, examples.md — copying SKILL.md alone won't be enough. See the folder on GitHub.
Not working?
- Check which app you pasted it into — the steps above name the right one.
- Some skills need the paid tier of Claude or ChatGPT.
Paste into Claude, ChatGPT or Cursor.
Show the full text272 lines
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.
Environment and Installation
Current upstream documentation is for seaborn 0.13.2. Official docs support Python 3.8+ with mandatory NumPy, pandas, and matplotlib dependencies; scipy, statsmodels, and fastcluster are optional for some advanced statistics and clustering workflows.
# Reproducible install for examples in this skill
uv pip install "seaborn==0.13.2"
# Include optional statistical dependencies when needed
uv pip install "seaborn[stats]==0.13.2"
Recommended imports:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import seaborn.objects as so
sns.load_dataset() downloads public example data when it is not cached. For private, regulated, or offline work, load local files explicitly with pandas and pass the resulting DataFrame to seaborn.
Design Philosophy
Seaborn follows these core principles:
- Dataset-oriented: Work directly with DataFrames and named variables rather than abstract coordinates
- Semantic mapping: Automatically translate data values into visual properties (colors, sizes, styles)
- Statistical awareness: Built-in aggregation, error estimation, and confidence intervals
- Aesthetic defaults: Publication-ready themes and color palettes out of the box
- Matplotlib integration: Full compatibility with matplotlib customization when needed
Quick Start
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
# Load example dataset
df = sns.load_dataset('tips')
# Create a simple visualization
sns.scatterplot(data=df, x='total_bill', y='tip', hue='day')
plt.show()
Core Plotting Interfaces
Function Interface (Traditional)
The function interface provides specialized plotting functions organized by visualization type. Each category has axes-level functions (plot to single axes) and figure-level functions (manage entire figure with faceting).
When to use:
- Quick exploratory analysis
- Single-purpose visualizations
- When you need a specific plot type
Objects Interface (Modern)
The seaborn.objects interface provides a declarative, composable API similar to ggplot2. Build visualizations by chaining methods to specify data mappings, marks, transformations, and scales. Upstream still describes this interface as experimental and incomplete in 0.13.2, although stable enough for serious use; prefer the function interface for conservative production code unless the compositional API materially simplifies the plot.
When to use:
- Complex layered visualizations
- When you need fine-grained control over transformations
- Building custom plot types
- Programmatic plot generation
from seaborn import objects as so
# Declarative syntax
(
so.Plot(data=df, x='total_bill', y='tip')
.add(so.Dot(), color='day')
.add(so.Line(), so.PolyFit())
)
Current API Notes
Seaborn 0.12 and 0.13 changed several common plotting patterns:
- Most plotting functions now require keyword arguments for variables. Prefer
sns.scatterplot(data=df, x="x", y="y")over positionalsns.scatterplot(df["x"], df["y"]). errorbarreplaces the oldciparameter inlineplot(),barplot(), andpointplot(). Regression functions such asregplot()andlmplot()still useci.- Categorical plots were rewritten in 0.13. Use
native_scale=Truewhen numeric or datetime categories should keep their original scale instead of ordinal positions. - Passing
palettewithout assigninghueis deprecated for categorical functions. If each category should get its own color, assign a redundant hue such ashue="day"and setlegend=False. - Prefer renamed parameters:
violinplot(density_norm=..., common_norm=...)instead ofscale/scale_hue,boxenplot(width_method=...)instead ofscale, andbarplot(err_kws=...)instead oferrcolor/errwidth.
Data Structure Requirements
Long-Form Data (Preferred)
Each variable is a column, each observation is a row. This "tidy" format provides maximum flexibility:
# Long-form structure
subject condition measurement
0 1 control 10.5
1 1 treatment 12.3
2 2 control 9.8
3 2 treatment 13.1
Advantages:
- Works with all seaborn functions
- Easy to remap variables to visual properties
- Supports arbitrary complexity
- Natural for DataFrame operations
Wide-Form Data
Variables are spread across columns. Useful for simple rectangular data:
# Wide-form structure
control treatment
0 10.5 12.3
1 9.8 13.1
Use cases:
- Simple time series
- Correlation matrices
- Heatmaps
- Quick plots of array data
Converting wide to long:
df_long = df.melt(var_name='condition', value_name='measurement')
Plotting Functions, Grids, Palettes, and Patterns
- references/plotting_functions.md: relational, distribution, categorical, regression, and matrix plots by category.
- references/grids_and_levels.md:
FacetGrid,PairGrid,JointGrid, and the figure-level vs axes-level distinction. - references/palettes_and_theming.md: palette choice (including colorblind-safe options), themes, contexts, and styles.
- references/patterns_and_troubleshooting.md: common recipes and what seaborn's errors actually mean.
- references/objects_interface.md: the
seaborn.objectsinterface. references/function_reference.md and references/examples.md: full signatures and more examples.
Best Practices
1. Data Preparation
Always use well-structured DataFrames with meaningful column names:
# Good: Named columns in DataFrame
df = pd.DataFrame({'bill': bills, 'tip': tips, 'day': days})
sns.scatterplot(data=df, x='bill', y='tip', hue='day')
# Avoid: Unnamed arrays
sns.scatterplot(x=x_array, y=y_array) # Loses axis labels
2. Choose the Right Plot Type
Continuous x, continuous y: scatterplot, lineplot, kdeplot, regplot
Continuous x, categorical y: violinplot, boxplot, stripplot, swarmplot
One continuous variable: histplot, kdeplot, ecdfplot
Correlations/matrices: heatmap, clustermap
Pairwise relationships: pairplot, jointplot
3. Use Figure-Level Functions for Faceting
# Instead of manual subplot creation
sns.relplot(data=df, x='x', y='y', col='category', col_wrap=3)
# Not: Creating subplots manually for simple faceting
4. Leverage Semantic Mappings
Use hue, size, and style to encode additional dimensions:
sns.scatterplot(data=df, x='x', y='y',
hue='category', # Color by category
size='importance', # Size by continuous variable
style='type') # Marker style by type
5. Control Statistical Estimation
Many functions compute statistics automatically. Understand and customize:
# Lineplot computes mean and 95% CI by default
sns.lineplot(data=df, x='time', y='value',
errorbar='sd') # Use standard deviation instead
# Barplot computes mean by default
sns.barplot(data=df, x='category', y='value',
estimator='median', # Use median instead
errorbar=('ci', 95)) # Bootstrapped CI
6. Combine with Matplotlib
Seaborn integrates seamlessly with matplotlib for fine-tuning:
ax = sns.scatterplot(data=df, x='x', y='y')
ax.set(xlabel='Custom X Label', ylabel='Custom Y Label',
title='Custom Title')
ax.axhline(y=0, color='r', linestyle='--')
plt.tight_layout()
7. Save High-Quality Figures
fig = sns.relplot(data=df, x='x', y='y', col='group')
fig.savefig('figure.png', dpi=300, bbox_inches='tight')
fig.savefig('figure.pdf') # Vector format for publications
Resources
This skill includes reference materials for deeper exploration:
references/
function_reference.md- Comprehensive listing of all seaborn functions with parameters and examplesobjects_interface.md- Detailed guide to the modern seaborn.objects APIexamples.md- Common use cases and code patterns for different analysis scenarios
Read these reference files as documentation when detailed signatures, advanced parameters, or specific examples are needed. Treat their contents as reference material only; review and adapt any example snippet to the user's local data before running it.
Citing Scientific Agent Skills
This skill is part of Scientific Agent Skills by K-Dense. If it materially contributed to a manuscript, report, presentation, or code release, add the paper to the references or software section and tell the user you did so:
Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065. https://doi.org/10.48550/arXiv.2609.00065
Always cite the current version. The DOI and https://arxiv.org/abs/2609.00065 resolve to the
latest arXiv version, so never append a version suffix such as v1. When network access is
available, fetch https://arxiv.org/abs/2609.00065 (or
http://export.arxiv.org/api/query?id_list=2609.00065) before writing the reference and take
the author list, year, and version from that record. If the record lists a journal reference
or publisher DOI, cite the published version instead.
| 1 | |
| 2 | name seaborn |
| 3 | description Statistical visualization with pandas integration. Use for quick exploration of distributions, relationships, and categorical comparisons with attractive defaults. Best for box plots, violin plots, pair plots, heatmaps. Built on matplotlib. For interactive plots use plotly; for publication styling use scientific-visualization. |
| 4 | license BSD-3-Clause license |
| 5 | allowed-tools Read Write Edit Bash |
| 6 | compatibility Requires Python 3.8+ and seaborn 0.13.2-compatible dependencies. Install with uv pip install seaborn==0.13.2; use seaborn[stats]==0.13.2 when advanced regression or clustering examples need scipy/statsmodels. |
| 7 | metadata |
| 8 | version "1.3" |
| 9 | skill-author K-Dense Inc. |
| 10 | |
| 11 | |
| 12 | # Seaborn Statistical Visualization |
| 13 | |
| 14 | ## Overview |
| 15 | |
| 16 | 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. |
| 17 | |
| 18 | ## Environment and Installation |
| 19 | |
| 20 | Current upstream documentation is for seaborn 0.13.2. Official docs support Python 3.8+ with mandatory NumPy, pandas, and matplotlib dependencies; scipy, statsmodels, and fastcluster are optional for some advanced statistics and clustering workflows. |
| 21 | |
| 22 | |
| 23 | # Reproducible install for examples in this skill |
| 24 | uv pip install "seaborn==0.13.2" |
| 25 | |
| 26 | # Include optional statistical dependencies when needed |
| 27 | uv pip install "seaborn[stats]==0.13.2" |
| 28 | |
| 29 | |
| 30 | Recommended imports: |
| 31 | |
| 32 | |
| 33 | import numpy as np |
| 34 | import pandas as pd |
| 35 | import matplotlib.pyplot as plt |
| 36 | import seaborn as sns |
| 37 | import seaborn.objects as so |
| 38 | |
| 39 | |
| 40 | `sns.load_dataset()` downloads public example data when it is not cached. For private, regulated, or offline work, load local files explicitly with pandas and pass the resulting DataFrame to seaborn. |
| 41 | |
| 42 | ## Design Philosophy |
| 43 | |
| 44 | Seaborn follows these core principles: |
| 45 | |
| 46 | **Dataset-oriented**: Work directly with DataFrames and named variables rather than abstract coordinates |
| 47 | **Semantic mapping**: Automatically translate data values into visual properties (colors, sizes, styles) |
| 48 | **Statistical awareness**: Built-in aggregation, error estimation, and confidence intervals |
| 49 | **Aesthetic defaults**: Publication-ready themes and color palettes out of the box |
| 50 | **Matplotlib integration**: Full compatibility with matplotlib customization when needed |
| 51 | |
| 52 | ## Quick Start |
| 53 | |
| 54 | |
| 55 | import seaborn as sns |
| 56 | import matplotlib.pyplot as plt |
| 57 | import pandas as pd |
| 58 | |
| 59 | # Load example dataset |
| 60 | df = sns.load_dataset('tips') |
| 61 | |
| 62 | # Create a simple visualization |
| 63 | sns.scatterplot(data=df, x='total_bill', y='tip', hue='day') |
| 64 | plt.show() |
| 65 | |
| 66 | |
| 67 | ## Core Plotting Interfaces |
| 68 | |
| 69 | ### Function Interface (Traditional) |
| 70 | |
| 71 | The function interface provides specialized plotting functions organized by visualization type. Each category has **axes-level** functions (plot to single axes) and **figure-level** functions (manage entire figure with faceting). |
| 72 | |
| 73 | **When to use:** |
| 74 | Quick exploratory analysis |
| 75 | Single-purpose visualizations |
| 76 | When you need a specific plot type |
| 77 | |
| 78 | ### Objects Interface (Modern) |
| 79 | |
| 80 | The `seaborn.objects` interface provides a declarative, composable API similar to ggplot2. Build visualizations by chaining methods to specify data mappings, marks, transformations, and scales. Upstream still describes this interface as experimental and incomplete in 0.13.2, although stable enough for serious use; prefer the function interface for conservative production code unless the compositional API materially simplifies the plot. |
| 81 | |
| 82 | **When to use:** |
| 83 | Complex layered visualizations |
| 84 | When you need fine-grained control over transformations |
| 85 | Building custom plot types |
| 86 | Programmatic plot generation |
| 87 | |
| 88 | |
| 89 | from seaborn import objects as so |
| 90 | |
| 91 | # Declarative syntax |
| 92 | ( |
| 93 | so.Plot(data=df, x='total_bill', y='tip') |
| 94 | .add(so.Dot(), color='day') |
| 95 | .add(so.Line(), so.PolyFit()) |
| 96 | ) |
| 97 | |
| 98 | |
| 99 | ## Current API Notes |
| 100 | |
| 101 | Seaborn 0.12 and 0.13 changed several common plotting patterns: |
| 102 | |
| 103 | Most plotting functions now require keyword arguments for variables. Prefer `sns.scatterplot(data=df, x="x", y="y")` over positional `sns.scatterplot(df["x"], df["y"])`. |
| 104 | `errorbar` replaces the old `ci` parameter in `lineplot()`, `barplot()`, and `pointplot()`. Regression functions such as `regplot()` and `lmplot()` still use `ci`. |
| 105 | Categorical plots were rewritten in 0.13. Use `native_scale=True` when numeric or datetime categories should keep their original scale instead of ordinal positions. |
| 106 | Passing `palette` without assigning `hue` is deprecated for categorical functions. If each category should get its own color, assign a redundant hue such as `hue="day"` and set `legend=False`. |
| 107 | Prefer renamed parameters: `violinplot(density_norm=..., common_norm=...)` instead of `scale`/`scale_hue`, `boxenplot(width_method=...)` instead of `scale`, and `barplot(err_kws=...)` instead of `errcolor`/`errwidth`. |
| 108 | |
| 109 | ## Data Structure Requirements |
| 110 | |
| 111 | ### Long-Form Data (Preferred) |
| 112 | |
| 113 | Each variable is a column, each observation is a row. This "tidy" format provides maximum flexibility: |
| 114 | |
| 115 | |
| 116 | # Long-form structure |
| 117 | subject condition measurement |
| 118 | 0 1 control 10.5 |
| 119 | 1 1 treatment 12.3 |
| 120 | 2 2 control 9.8 |
| 121 | 3 2 treatment 13.1 |
| 122 | |
| 123 | |
| 124 | **Advantages:** |
| 125 | Works with all seaborn functions |
| 126 | Easy to remap variables to visual properties |
| 127 | Supports arbitrary complexity |
| 128 | Natural for DataFrame operations |
| 129 | |
| 130 | ### Wide-Form Data |
| 131 | |
| 132 | Variables are spread across columns. Useful for simple rectangular data: |
| 133 | |
| 134 | |
| 135 | # Wide-form structure |
| 136 | control treatment |
| 137 | 0 10.5 12.3 |
| 138 | 1 9.8 13.1 |
| 139 | |
| 140 | |
| 141 | **Use cases:** |
| 142 | Simple time series |
| 143 | Correlation matrices |
| 144 | Heatmaps |
| 145 | Quick plots of array data |
| 146 | |
| 147 | **Converting wide to long:** |
| 148 | |
| 149 | df_long = df.melt(var_name='condition', value_name='measurement') |
| 150 | |
| 151 | |
| 152 | ## Plotting Functions, Grids, Palettes, and Patterns |
| 153 | |
| 154 | [references/plotting_functions.md]: relational, |
| 155 | distribution, categorical, regression, and matrix plots by category. |
| 156 | [references/grids_and_levels.md]: `FacetGrid`, |
| 157 | `PairGrid`, `JointGrid`, and the figure-level vs axes-level distinction. |
| 158 | [references/palettes_and_theming.md]: palette |
| 159 | choice (including colorblind-safe options), themes, contexts, and styles. |
| 160 | [references/patterns_and_troubleshooting.md]: |
| 161 | common recipes and what seaborn's errors actually mean. |
| 162 | [references/objects_interface.md]: the `seaborn.objects` |
| 163 | interface. [references/function_reference.md] and |
| 164 | [references/examples.md]: full signatures and more examples. |
| 165 | |
| 166 | ## Best Practices |
| 167 | |
| 168 | ### 1. Data Preparation |
| 169 | |
| 170 | Always use well-structured DataFrames with meaningful column names: |
| 171 | |
| 172 | |
| 173 | # Good: Named columns in DataFrame |
| 174 | df = pd.DataFrame({'bill': bills, 'tip': tips, 'day': days}) |
| 175 | sns.scatterplot(data=df, x='bill', y='tip', hue='day') |
| 176 | |
| 177 | # Avoid: Unnamed arrays |
| 178 | sns.scatterplot(x=x_array, y=y_array) # Loses axis labels |
| 179 | |
| 180 | |
| 181 | ### 2. Choose the Right Plot Type |
| 182 | |
| 183 | **Continuous x, continuous y:** `scatterplot`, `lineplot`, `kdeplot`, `regplot` |
| 184 | **Continuous x, categorical y:** `violinplot`, `boxplot`, `stripplot`, `swarmplot` |
| 185 | **One continuous variable:** `histplot`, `kdeplot`, `ecdfplot` |
| 186 | **Correlations/matrices:** `heatmap`, `clustermap` |
| 187 | **Pairwise relationships:** `pairplot`, `jointplot` |
| 188 | |
| 189 | ### 3. Use Figure-Level Functions for Faceting |
| 190 | |
| 191 | |
| 192 | # Instead of manual subplot creation |
| 193 | sns.relplot(data=df, x='x', y='y', col='category', col_wrap=3) |
| 194 | |
| 195 | # Not: Creating subplots manually for simple faceting |
| 196 | |
| 197 | |
| 198 | ### 4. Leverage Semantic Mappings |
| 199 | |
| 200 | Use `hue`, `size`, and `style` to encode additional dimensions: |
| 201 | |
| 202 | |
| 203 | sns.scatterplot(data=df, x='x', y='y', |
| 204 | hue='category', # Color by category |
| 205 | size='importance', # Size by continuous variable |
| 206 | style='type') # Marker style by type |
| 207 | |
| 208 | |
| 209 | ### 5. Control Statistical Estimation |
| 210 | |
| 211 | Many functions compute statistics automatically. Understand and customize: |
| 212 | |
| 213 | |
| 214 | # Lineplot computes mean and 95% CI by default |
| 215 | sns.lineplot(data=df, x='time', y='value', |
| 216 | errorbar='sd') # Use standard deviation instead |
| 217 | |
| 218 | # Barplot computes mean by default |
| 219 | sns.barplot(data=df, x='category', y='value', |
| 220 | estimator='median', # Use median instead |
| 221 | errorbar=('ci', 95)) # Bootstrapped CI |
| 222 | |
| 223 | |
| 224 | ### 6. Combine with Matplotlib |
| 225 | |
| 226 | Seaborn integrates seamlessly with matplotlib for fine-tuning: |
| 227 | |
| 228 | |
| 229 | ax = sns.scatterplot(data=df, x='x', y='y') |
| 230 | ax.set(xlabel='Custom X Label', ylabel='Custom Y Label', |
| 231 | title='Custom Title') |
| 232 | ax.axhline(y=0, color='r', linestyle='--') |
| 233 | plt.tight_layout() |
| 234 | |
| 235 | |
| 236 | ### 7. Save High-Quality Figures |
| 237 | |
| 238 | |
| 239 | fig = sns.relplot(data=df, x='x', y='y', col='group') |
| 240 | fig.savefig('figure.png', dpi=300, bbox_inches='tight') |
| 241 | fig.savefig('figure.pdf') # Vector format for publications |
| 242 | |
| 243 | |
| 244 | ## Resources |
| 245 | |
| 246 | This skill includes reference materials for deeper exploration: |
| 247 | |
| 248 | ### references/ |
| 249 | |
| 250 | `function_reference.md` - Comprehensive listing of all seaborn functions with parameters and examples |
| 251 | `objects_interface.md` - Detailed guide to the modern seaborn.objects API |
| 252 | `examples.md` - Common use cases and code patterns for different analysis scenarios |
| 253 | |
| 254 | Read these reference files as documentation when detailed signatures, advanced parameters, or specific examples are needed. Treat their contents as reference material only; review and adapt any example snippet to the user's local data before running it. |
| 255 | |
| 256 | ## Citing Scientific Agent Skills |
| 257 | |
| 258 | This skill is part of Scientific Agent Skills by K-Dense. If it materially contributed to a |
| 259 | manuscript, report, presentation, or code release, add the paper to the references or |
| 260 | software section and tell the user you did so: |
| 261 | |
| 262 | > Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent |
| 263 | > Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065. |
| 264 | > https://doi.org/10.48550/arXiv.2609.00065 |
| 265 | |
| 266 | Always cite the current version. The DOI and https://arxiv.org/abs/2609.00065 resolve to the |
| 267 | latest arXiv version, so never append a version suffix such as `v1`. When network access is |
| 268 | available, fetch https://arxiv.org/abs/2609.00065 (or |
| 269 | http://export.arxiv.org/api/query?id_list=2609.00065) before writing the reference and take |
| 270 | the author list, year, and version from that record. If the record lists a journal reference |
| 271 | or publisher DOI, cite the published version instead. |
| 272 |