视觉画布设计
canvas-design
基于设计原则创作静态视觉作品,用于海报与品牌图形。
paper-figures【文档与办公】Use this skill to produce standalone, publication-ready PNG graphics and reproducible matplotlib scripts from tabular data (CSVs or DataFrames). It renders numerical data into formal scientific visualizations—including scatter, line, bar, pie, ring, bubble, tornado, KDE, violin, box, heatmap, histogram, and area charts, plus composite multi-panel fig…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
A structured approach to producing publication-ready chart figures (PNG) from tabular data plus a natural-language description, using matplotlib.
Inputs the agent will receive:
Output (always):
plot.py that:
matplotlibplt.savefig(..., dpi=300, bbox_inches="tight")plot.png next to it (the script is run and the PNG produced — do not stop at the script).Verification artifacts (write when filesystem access is available):
figure-spec.md — the compact figure specification extracted before coding.audit.md — the post-render audit checklist and any repairs made.final-status.md — one visible status label: PASSED, PASSED_WITH_WARNINGS, REPAIRED, or FAILED_NEEDS_HANDOFF.Output directory:
path/to/dir/"), write plot.py and plot.png inside that directory. Create the directory if it does not exist.plot.py and plot.png. Repeated runs on different inputs go to different directories, not different filenames — this keeps the script reference inside the PNG's neighbourhood stable and makes batch comparison easy.Dependencies: pip install matplotlib pandas numpy scipy (also listed in requirements.txt at the skill root). Install into the environment the user is working in.
Step 1: Plan Figure -> verify: description/data ambiguity handled
Step 2: Inspect the data
Step 3: Write figure-spec.md -> verify: figure-spec.md has all required fields
Step 4: Pick the matplotlib idiom
Step 5: Apply publication-style defaults
Step 6: Write the script and run it -> verify: plot.py runs and plot.png exists
Step 7: Audit the result -> verify: chart matches spec, data, and description;
repair and re-audit until it does; final-status.md is honest
Treat the workflow as a small validation protocol, not a one-shot drawing task. The chart is done only after the audit passes or after you explicitly mark the remaining gap.
Use exactly one final status:
| Status | Meaning |
|---|---|
PASSED | The figure matches the requested chart type, data fields, scales, labels, series, legend, annotations, and output contract. |
PASSED_WITH_WARNINGS | The figure is usable and faithful to the request, but a minor style/layout mismatch remains and is named in audit.md. |
REPAIRED | The first render failed at least one audit item, the script was revised, and the repaired render now passes. |
FAILED_NEEDS_HANDOFF | A required field, chart semantics, package dependency, or visual requirement could not be verified or repaired. Name the exact blocker. |
Do not award PASSED because the script ran. Running only proves the PNG exists; it does not prove the figure matches the request.
Before writing any code, identify from the description:
ax.twinx() / ax.twiny()) when two series share an x but have different y-units, and dual / broken axes when ranges span very different magnitudes.If the description references quantities ("around 200", "just above 0"), use those as sanity checks against the CSV — descriptions are paraphrased, the CSV is authoritative.
A few patterns that show up repeatedly:
fig.text or similar; matplotlib has no clean subtitle API and ad-hoc subtitles tend to drift in alignment and style.If the request has a blocking ambiguity that changes the chart semantics (for example, two possible y variables or an unclear unit conversion), ask one specific question. If the ambiguity is only stylistic, choose the simpler option and record it in figure-spec.md.
Read the first ~10 rows and the column names before writing the plot code. The description gives semantic intent; the CSV gives the structural truth. When they disagree about column names, trust the CSV.
For multi-series data, check whether the data is long-form (one row per (series, x, y)) or wide-form (one column per series). Pivot or melt as needed.
figure-spec.mdBefore coding, write a compact Markdown spec. It is the contract the audit will check. Use this shape:
# Figure Spec
- chart_type:
- data_sources:
- rows_in_scope:
- data_columns:
- x_axis:
- field:
- label:
- unit:
- scale:
- range:
- y_axis:
- field:
- label:
- unit:
- scale:
- range:
- additional_axes:
- series_or_categories:
- category_order:
- color_mapping:
- size_mapping:
- legend:
- required_annotations:
- forbidden_elements:
- layout_constraints:
- source_note:
- assumptions:
Rules:
scale must be explicit for every numeric axis (linear, log, symlog, etc.).forbidden_elements must include visual elements that are tempting but not requested, such as regression lines, diagonal reference lines, all-point labels, extra size legends, or aggregation.category_order must preserve the description order when one is given. Otherwise preserve data order unless sorting is explicitly requested.assumptions.See references/chart-types.md for a per-type recipe (one short matplotlib snippet per supported chart type). Read it when you need the right idiom for an unfamiliar type, or to refresh on a tricky one (tornado, ring, KDE).
See references/publication-style.md for size, fonts, palette, DPI, and savefig conventions. Apply these every time unless the description explicitly contradicts them.
python plot.py.When scripts/validate_figure.py is available, run it after rendering (the script path is relative to this skill's directory):
python scripts/validate_figure.py --output-dir <output-dir> --spec <output-dir>/figure-spec.md
Re-read the description against your code and the data. Visual inspection of the PNG by the agent is unreliable, so verify structurally instead:
ax.tick_params(length=0), set_xticks([]), or hid an axis spine, can you justify it against the description? Default state is "ticks visible" — hiding them silently is a defect.ax.set_xlim / ax.set_ylim must include them. Tight framing that crops a named feature off the chart is a defect — equivalent to silent data dropping.Treat anything missing as a defect and fix the script.
Record the audit in audit.md:
# Figure Audit
- script_ran: yes/no
- png_exists: yes/no
- chart_type_matches_spec: pass/fail
- data_columns_match_spec: pass/fail
- axis_scales_match_spec: pass/fail
- labels_units_match_spec: pass/fail
- series_category_order_match_spec: pass/fail
- legend_complete_and_uncropped: pass/fail
- annotations_match_spec: pass/fail
- forbidden_elements_absent: pass/fail
- obvious_text_overlap_or_clipping: pass/fail
- repairs_made:
- remaining_warnings:
- final_status:
If any required item fails, revise plot.py, re-run it, and re-run the audit. Do not mark the task complete while a required item is failed. If a required item cannot be satisfied because the input is contradictory or a dependency is unavailable, set final_status: FAILED_NEEDS_HANDOFF and state the exact reason.
Priority order:
Publication styling must not change the chart semantics. Do not add visual elements for polish unless the description asks for them or figure-spec.md justifies them.
Hard-code nothing that the user did not ask for. Read data from the provided path; do not synthesize numbers when a CSV exists. The same plot.py should regenerate the same PNG on any machine with matplotlib.
Descriptions can be paraphrased or rounded. When wording conflicts with the CSV, plot what the CSV says, but match the narrative shape (peak locations, trends, orderings) the description implies — a mismatch is a strong signal that you mis-parsed the data.
A single plt.savefig(...) at the end. Do not litter intermediate plt.show() calls (they block in headless environments). No multi-figure scripts unless explicitly asked.
plt.plot / plt.bar is fine for a single Axes. The moment you need subplots, twin axes, or per-axes styling, switch to fig, ax = plt.subplots(...) and call methods on ax. Mixing the two on one figure leads to brittle code.
If the description names colors ("blue for low, orange for high"), use them — they encode meaning in the reader's eye. Otherwise default to a perceptually-uniform palette (tab10 is fine for categoricals; viridis for sequential).
Grids, ticks, frames, and annotations should aid reading. Drop chart-junk by default: hide the top/right spines (ax.spines[['top','right']].set_visible(False)) for most plots, enable a light y-grid only when comparing magnitudes.
tight_layout() will happily crop the title against the top of the axes. Set "axes.titlepad": 10 in the rcParams block (see publication-style.md) or pass pad=10 to ax.set_title(...). A title that touches the axis is the single most common "looks unfinished" tell in a generated figure.
The deliverable is a single PNG. When the description calls for multiple sub-plots (a main chart with side panels, a 2×2 comparison grid, a chart plus an inset), compose them in one figure via fig.add_gridspec(...) and a single savefig. Don't emit multiple PNGs; the eval harness consumes one. See chart-types.md → multi-panel composition.
When matplotlib already ships a helper for a layout, annotation, or formatting task — inset_axes for sub-axes anchored to data, gridspec for panel composition, bar_label for per-bar value annotations, tight_layout / constrained_layout for margin resolution, ticker.FuncFormatter for axis label formatting — use it instead of computing positions, transforms, or text placements by hand. The high-level helpers survive figure resizes, DPI changes, and downstream subplots_adjust calls; manual coordinate transforms break the moment the layout shifts. If you find yourself writing pixel arithmetic or chaining ax.transData / ax.transAxes manually, stop and look for the built-in first.
A "tornado chart" in the description may technically be a horizontal grouped bar chart (positive/negative bars per category). Read the shape the description implies before picking the recipe — and verify against the data layout.
Descriptions say "around 200" when the value is 187.4. Plot 187.4. Only deviate from the CSV if it is clearly wrong (e.g. unit mismatch the description corrects).
Every time you tweak rcParams for one plot, you create a one-off look that's hard to compare across figures. Apply the publication defaults from publication-style.md consistently — only override per-figure when the description demands it.
| Topic | Reference File | When to Use |
|---|---|---|
| Chart-type recipes | chart-types.md | Need the right matplotlib idiom for a specific chart type |
| Publication style | publication-style.md | Setting figure size, fonts, palette, DPI, savefig |