This skill should be used when the user asks to "create a plot", "make a chart", "visualize data", "create a heatmap", "make a scatter plot", "plot time series", "create publication figures", "customize plot styling", "use matplotlib", "use seaborn", or needs guidance on Python data visualization, statistical graphics, or figure export.
This skill inherits all available tools. When active, it can use any tool Claude has access to.
references/api-reference.mdreferences/example.mdreferences/matplotlib-fundamentals.mdreferences/plot-types.mdreferences/seaborn-fundamentals.mdreferences/seaborn-objects.mdreferences/styling.mdreferences/troubleshooting.mdscripts/plot_template.pyscripts/style_configurator.pyworkflows/example.mdPython data visualization with matplotlib and seaborn for creating publication-quality figures, statistical graphics, and exploratory visualizations.
Matplotlib is the foundational plotting library. Use it for:
Seaborn builds on matplotlib for statistical visualization. Use it for:
Combined approach: Use seaborn for the main visualization, then customize with matplotlib.
Object-oriented interface (recommended):
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(10, 6))
ax.plot(x, y, linewidth=2, label='data')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.legend()
plt.savefig('figure.png', dpi=300, bbox_inches='tight')
pyplot interface (quick exploration only):
plt.plot(x, y)
plt.xlabel('X Label')
plt.show()
Always use the object-oriented interface for production code.
Axes-level functions plot to a single matplotlib Axes:
ax= parameter for placementscatterplot, histplot, boxplot, heatmapFigure-level functions manage entire figures with faceting:
col, row parameters for small multiplesrelplot, displot, catplot, lmplot, jointplot, pairplotimport seaborn as sns
# Axes-level: integrates with matplotlib
fig, axes = plt.subplots(1, 2)
sns.scatterplot(data=df, x='x', y='y', ax=axes[0])
sns.histplot(data=df, x='x', ax=axes[1])
# Figure-level: automatic faceting
sns.relplot(data=df, x='x', y='y', col='category', hue='group')
Map data variables to visual properties automatically:
hue - Color encodingsize - Point/line sizestyle - Marker/line stylecol, row - Facet into subplotssns.scatterplot(data=df, x='x', y='y',
hue='category', # Color by category
size='importance', # Size by value
style='type') # Different markers
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
sns.set_theme(style='whitegrid', context='paper', font_scale=1.1)
# Simple seaborn plot
fig, ax = plt.subplots(figsize=(10, 6))
sns.scatterplot(data=df, x='total_bill', y='tip', hue='day', ax=ax)
# Or figure-level with faceting
g = sns.relplot(data=df, x='x', y='y', col='category', kind='scatter')
ax.set_xlabel('Total Bill ($)', fontsize=12)
ax.set_ylabel('Tip ($)', fontsize=12)
ax.set_title('Restaurant Tips', fontsize=14)
ax.legend(title='Day', bbox_to_anchor=(1.05, 1))
plt.savefig('figure.png', dpi=300, bbox_inches='tight')
plt.savefig('figure.pdf') # Vector format for publications
| Data Type | Recommended | Alternatives |
|---|---|---|
| Distribution (1 variable) | histplot, kdeplot | boxplot, violinplot |
| Relationship (2 continuous) | scatterplot | regplot, hexbin |
| Time series | lineplot | plot with dates |
| Categorical comparison | barplot, boxplot | violinplot, stripplot |
| Correlation matrix | heatmap | clustermap |
| Pairwise relationships | pairplot | PairGrid |
| Bivariate with marginals | jointplot | JointGrid |
For detailed plot type examples, see references/plot-types.md.
constrained_layout=True - Prevents overlapping elementsfig, ax = plt.subplots(figsize=(10, 6))plt.close(fig) to prevent memory leaksviridis, plasma, cividisjet is not perceptually uniformviridis, cividis, or colorblind palettecoolwarm, RdBu for data with meaningful zerodpi=300bbox_inches='tight' - Removes excess whitespaceerrorbar='sd', errorbar=('ci', 95)stripplot with boxplotfig, axes = plt.subplots(2, 2, figsize=(12, 10), constrained_layout=True)
sns.scatterplot(data=df, x='x', y='y', ax=axes[0, 0])
sns.histplot(data=df, x='x', ax=axes[0, 1])
sns.boxplot(data=df, x='cat', y='y', ax=axes[1, 0])
sns.heatmap(corr_matrix, ax=axes[1, 1], cmap='coolwarm', center=0)
sns.set_theme(style='ticks', context='paper', font_scale=1.1)
fig, ax = plt.subplots(figsize=(8, 6))
sns.boxplot(data=df, x='treatment', y='response', ax=ax)
sns.stripplot(data=df, x='treatment', y='response', color='black', alpha=0.3, ax=ax)
ax.set_xlabel('Treatment Condition')
ax.set_ylabel('Response (units)')
sns.despine()
plt.savefig('figure.pdf', dpi=300, bbox_inches='tight')
g = sns.relplot(
data=df, x='x', y='y',
hue='treatment', style='batch',
col='timepoint', col_wrap=3,
kind='line', height=3, aspect=1.5
)
g.set_axis_labels('X Variable', 'Y Variable')
g.set_titles('{col_name}')
This skill includes helper scripts:
scripts/plot_template.py - Template demonstrating various plot typesscripts/style_configurator.py - Interactive style configuration utilityFor detailed information, load specific references:
oaps skill context python-dataviz --references <name>
| Reference | Content |
|---|---|
matplotlib-fundamentals | Core matplotlib concepts, hierarchy, common operations |
seaborn-fundamentals | Seaborn design, data structures, function categories |
plot-types | Comprehensive plot type guide with examples |
styling | Colormaps, palettes, themes, typography |
api-reference | Quick reference for common functions and parameters |
troubleshooting | Common issues and solutions |
seaborn-objects | Modern seaborn.objects declarative interface |