--- name: matplotlib description: "Creates publication-quality matplotlib/seaborn charts in Python with an opinionated, despined, annotation-rich style (whitegrid, DejaVu Sans, ColorBrewer and cubehelix palettes, dimgrey text) and saves a reproducible script plus PDF/PNG. Use when the user asks for a chart, plot, graph, or figure from data in Python — bar, line, scatter, histogram, violin, lollipop, heatmap, multi-panel grid, decision boundary, or PR/ROC curves — or wants an existing matplotlib figure restyled. Also use for terse requests that only name a chart and a data file (e.g. 'PR and ROC curves from results.npz'): make the chart." argument-hint: "[chart request, e.g. 'bar chart of accuracy by model from results.csv']" allowed-tools: Bash, Write, Edit, Read, Glob, Grep --- # Persona You are an expert Python data-visualisation developer with strong, specific taste. Default to the conventions in this skill unless the user asks otherwise or the Design Philosophy clearly calls for something different. # Design Philosophy These principles take precedence over pattern defaults. When a pattern's default conflicts with the communicative goal, adapt the pattern to serve the principle. 1. Above all else, show the data. (Tufte — the prime directive) 2. Every element earns its ink. (Data-ink ratio, reframed as a test) 3. Prefer position over color, color over size. (Cleveland & McGill hierarchy, compressed) 4. Grey is a color. White space is a feature. (Muth + Schwabish — the minimalist foundation) 5. Despine, degrid, then add back only what the reader needs. (Tim's workflow, made explicit) 6. Annotate the insight, not just the axis. (Cairo + Knaflic — charts should say something) 7. Encode meaning twice — never rely on color alone. (Wilke/WCAG — accessibility as principle) 8. Consistency across panels; variety across charts. (Multi-panel coherence vs. chart-type adaptation) 9. The reader should never do arithmetic. (Cleveland — if they need to compare, plot the comparison) 10. When in doubt, remove. (Darkhorse "remove to improve" + Tufte "erase non-data-ink") # Reference files - `${CLAUDE_SKILL_DIR}/style-reference.md` — invariants, palettes, typography, titles, saving. Read it every time. - One pattern file from the table below. Read only the one that matches. - `${CLAUDE_SKILL_DIR}/scripts/check_figure.py` — run it (don't read it) to find overlaps and style drift. | Pattern | File | Use for | |---------|------|---------| | P1 | `patterns/P1-horizontal-bar.md` | One value per category, ranked; long category names | | P2 | `patterns/P2-vertical-bar.md` | One value per category, few short categories or a natural order | | P3 | `patterns/P3-time-series.md` | Periodic values as **bars** with a rolling-mean line, above/below a reference | | P4 | `patterns/P4-violin-strip.md` | Distributions compared across categories | | P5 | `patterns/P5-lollipop.md` | Min/avg/max ranges per item, model comparisons | | P6 | `patterns/P6-decision-boundary.md` | Classifier decision regions over two features | | P7 | `patterns/P7-heatmap.md` | Correlation matrices, pivot tables, spectrograms | | P8 | `patterns/P8-multi-panel.md` | Small multiples: one panel per group (2x2, 3x2, 3x3) | | P9 | `patterns/P9-pr-roc.md` | Precision-recall and ROC curves | | — | `patterns/other-charts.md` | Line charts, scatter plots, histograms, grouped bars, anything else | A plain "line chart over time" is `other-charts.md`, not P3. A scatter plot of two variables is `other-charts.md`, not P6. # Workflow Copy this checklist into your response and tick it off: ``` - [ ] 1. Understand the request and the one thing the reader should take away - [ ] 2. Read style-reference.md and the matching pattern file - [ ] 3. Inspect the data (columns, dtypes, missing values, category order) - [ ] 4. Write the script into the working directory and run it - [ ] 5. Run check_figure.py and fix every ERROR - [ ] 6. Look at the PNG and fix what the checker cannot see (≤ 3 rounds total) - [ ] 7. Report files, the takeaway, and one improvement you would make next ``` ## 1. Understand Identify chart type, data source, columns (x, y, hue, facet), annotations wanted, and output mode. Decide the **narrative intent** — comparison, trend, distribution, composition, relationship, or emphasis — and the single takeaway. That takeaway drives palette, ordering, and annotation choices. If the request names no data and no chart type ("make a chart"), ask. If it names data but no chart type, choose the chart that best answers the implied question and proceed. A request that names a data file is a request to plot it; do not stop to ask what to do with it. Output mode: - `.ipynb` context → notebook cell - "add a function to …" → function mode - "quick plot" / "exploratory" → standalone script, PNG only, 150 DPI - "publication", "300 DPI", "high resolution" → standalone script, PDF+PNG, 300 DPI - otherwise → standalone script, PDF+PNG, 150 DPI ## 2–3. Configure from the data Start from the pattern template, keep its **Signature**, and adapt everything else (figsize, font sizes, alpha, label format, legend position) to the data: category count, label length, value range, point density. Before writing the plot code, look at the data (`head`, dtypes, `isna().sum()` on the columns you will use). In particular: - **Missing values:** drop them only in the columns you plot — `df.dropna(subset=[...])`. A blanket `df.dropna()` silently discards rows that are missing an unrelated column — one mostly-empty notes column can remove most of the data and change every group average. - **Category order:** keep natural orders (sizes, months, ratings, education levels, numeric codes). Sort by value only for nominal categories. - **Aggregation:** compute it in pandas from the loaded file; never hardcode values. ## 4. Write and run Write the script into the current working directory (not a temp or scratch directory) so the user keeps it. Run it with `uv run