Build publication-quality Matplotlib figures for scientific Python. Use when plotting experiment or analysis results, multi-panel figures, journal-sized layouts, tick formatting, legends (fancy/plain, placement, compact handles), point annotations, inset zooms, twin axes, colored spines/ticks, colorblind-safe palettes, PNG/PDF export, or SciencePlots styling. Triggers on matplotlib, pyplot, subplots, savefig, legend, annotate, inset, twinx, scientific figures, panel labels.
fig, ax = plt.subplots() (or subplot_mosaic / GridSpec), then call methods on ax. Avoid plt.plot when multiple axes exist; implicit pyplot targets the wrong axis by default. See Practical Data Science: explicit vs implicit syntax and basic plotting.Time (s), Voltage (V)). Match tick style to audience: disable offset/scientific clutter when plain decimals read better; use scientific or engineering notation when magnitudes span orders. Details: .bbox_inches="tight" when labels are clipped; transparent=True for PNG overlays and slides. Prefer vector PDF/SVG for final print when the journal allows. See reference-export-naming.md.(a), (b) for multi-panel figures: consistent placement, bold, same size as body or slightly larger. See Matplotlib: labelling subplots and reference-axes-ticks.md.Axes or Figure and return the same object after mutation. See reference-api-patterns.md.| Resource | Role |
|---|---|
| general-python | uv, ty, export scripts, python-reviewer |
| numpy-scientific | Array inputs to plots |
| dataframes | df.plot(ax=ax) and Polars-to-pandas at plot boundaries |
| numpy-docstrings | Docstrings for plotting helpers and figure builders |
| Topic | File |
|---|---|
Subplots vs GridSpec vs subplot_mosaic; assembling panels | reference-layout.md |
| Axis labels, units, ticks, scientific notation, panel labels | reference-axes-ticks.md |
| Spine/tick/label color, twin-axis styling | reference-axes-appearance.md |
| Legends: fancy frame, title, placement, compact handles | reference-legend-style.md |
| Point annotations, inset zooms, twin / secondary axes | reference-annotations-insets-twins.md |
| Color maps, cycles, colorblind safety, data types | reference-color.md |
savefig, transparency, DPI, auto-increment filenames | reference-export-naming.md |
| Journal widths, composition, storytelling | reference-journal-layout.md |
SciencePlots / style sheets; pandas .plot(ax=ax) | reference-styles-pandas.md |
ax.set(...). See A figure in 10 pieces.zorder and distinct color when mixing plot / scatter / bar on one axes (basic plotting).bbox_to_anchor outside or ncol below when the data region is crowded (reference-legend-style.md).annotate styling; insets for zoom only when the story needs local detail (reference-annotations-insets-twins.md).Split into separate figures when panels are reused across talks vs papers, or when layout constraints differ (poster vs manuscript). Compose in a layout script or document (LaTeX/Quarto) when the page design, not matplotlib, should own margins and alignment.
Functions that take/return Axes / Figure | reference-api-patterns.md |
Rasterized PDF, align_labels, CI, memory | reference-advanced.md |
df.plot(..., ax=ax) returns matplotlib artists; refine with ax methods. See Plotting with Pandas.