# matplotlib

> Low-level plotting library for full customization — use when you need fine-grained control over every plot element, creating novel plot types, or integrating with specific scientific workflows for PNG/PDF/SVG export.

**Use case**: Fine-grained control over every element of a Python plot

**Canonical URL**: https://agentcookbooks.com/skills/matplotlib/

**Topics**: claude-code, skills, science, data-science

**Trigger phrases**: "plot this with matplotlib", "create a custom figure", "matplotlib axes", "export plot to PDF", "annotate this chart"

**Source**: [K-Dense AI](https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/scientific-skills/matplotlib)

**License**: MIT

---

## What it does

`matplotlib` is a Claude Code skill from K-Dense AI's [scientific-agent-skills repo](https://github.com/K-Dense-AI/scientific-agent-skills). It turns Claude into a matplotlib expert covering both the pyplot interface (MATLAB-style) and the object-oriented API (Figure/Axes) — with guidance on the full matplotlib hierarchy, customization of every visual element, multi-panel layouts, and export to PNG, PDF, SVG, and EPS.

A session produces working Python code for the requested visualization — from simple line plots to complex multi-axis figures with insets, custom tick formatters, log scales, colorbars, and annotation arrows.

## When to use it

Reach for it when:

- You need precise control over a specific plot element that higher-level libraries (seaborn, plotly) abstract away
- You're creating a novel plot type not natively supported by seaborn or other wrappers
- You need export to a specific format (EPS for journal submission, SVG for vector editing) at a specific DPI

When *not* to reach for it:

- Quick statistical plots with sensible defaults — use `seaborn`
- Publication-ready multi-panel figures with journal styling — use `scientific-visualization`
- Interactive plots for web deployment — consider plotly

## Install

Copy the `SKILL.md` from K-Dense AI's [matplotlib folder](https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/scientific-skills/matplotlib) into `.claude/skills/matplotlib/` in your project.

Trigger phrases: "plot this with matplotlib", "create a custom figure", "matplotlib axes", "export plot to PDF".

## What a session looks like

A typical session has three phases:

1. **Plot specification.** Describe the data and the desired visualization — plot type, axes, number of panels, and any specific styling or annotation requirements.
2. **Code generation.** Claude generates matplotlib code using the object-oriented API (Figure/Axes) for flexibility, with explicit setup of figure size, DPI, font properties, and color choices.
3. **Refinement.** You run the code, describe any adjustments (axis limits, label positioning, legend placement), and Claude makes targeted edits to specific Artist objects rather than regenerating the full figure.

## Receipts

**Where it works well:**
- Custom annotation layers on top of existing plots — arrows, text boxes, span overlays, bracket markers — where Claude knows every relevant Artist method
- Precise axis control for log-scale plots, dual y-axes, and broken axis figures that break seaborn's abstractions

**Where it backfires:**
- Complex interactive plots — matplotlib's animation and widget interfaces require more back-and-forth than plotly's declarative model
- First-pass figure aesthetics for non-technical audiences; matplotlib defaults are functional but not polished without explicit styling

**Pattern that works:** always use the object-oriented API (fig, ax = plt.subplots()) rather than pyplot state machine; it makes every subsequent edit precise and avoids the global state bugs that make matplotlib debugging frustrating.

## Source and attribution

Originally authored by [K-Dense Inc.](https://github.com/K-Dense-AI). The canonical SKILL.md lives in the [`matplotlib` folder](https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/scientific-skills/matplotlib) of their public scientific-agent-skills repository.

License: MIT. Install, adapt, and redistribute with attribution preserved.

This page documents the skill from a practitioner's perspective. For the formal spec and any updates, defer to the source repo.