Skip to main content

FigWorks

CI PyPI Python License: MIT

A Python suite for reproducible, reviewable, and editable scientific figures.

FigWorks brings together Matplotlib and Plotly plots, VecTeX equations, VecView 3D scenes, VecWire circuit schematics, and native SVG annotations on a physical page. Each producer is independently useful; FigWorks composes their output into a publication figure.

  • Reproducible: regenerate figures from source, with deterministic SVG for identical inputs in the same toolchain and font environment.
  • Reviewable: inspect the Python, styling, and semantic SVG in version control. Named panels and elements make changes traceable.
  • Editable: keep vector paths, text, equations, and groups available for final adjustments in Inkscape. VecTeX retains TeX source for TexText editing.

Figures you own, even when AI helped make them. An assistant can draft the script, but what you keep is plain Python in your repository and SVG with named parts: every number traces back to code you can check, every label can be changed by hand, and the figure rebuilds from source whenever you need it.

Documentation · Gallery · Quick start · Examples · Agent skill · The suite · Report an issue

A four-panel graphene figure: the honeycomb lattice with its unit cell, both bands as 3D surfaces touching at the Dirac points, the band structure along high-symmetry lines, and the density of states

The action potential: sodium and potassium channels in a membrane, the Hodgkin-Huxley equations, a spike train, the conductances, and the firing threshold Shocks in a production network: the network map under a chip shock, the bullwhip effect, and aggregate volatility A vacuum triode as a mid-century tube manual drew it: the electrode assembly cut away in ink, and its plate and mutual characteristics on graph paper

Dirac electrons in graphene, styled for Physical Review; the action potential and shocks in a production network, styled for Nature; and a vacuum triode in a style of its own, a mid-century engineering handbook's. Figures from physics, neuroscience, economics, and electronics, each built by one self-contained script.

See all ten figures and their code in the gallery →

The graphene figure is two VecView scenes and two Matplotlib plots, labelled with VecTeX. The sources share nothing but a method, and FigWorks composes them in a few lines:

theme = load_theme("aps")
fig = Figure(width=theme.page["double"], height="121mm", theme=theme)
panels = fig.grid(  # a and b
    [["lattice", "zone"]],
    width_ratios=(1, 1.15),
    margins=("7mm", "3mm", "60mm", "6mm"),  # top, right, bottom, left
    gap="8mm",
)
panels |= fig.grid(  # c and d: a row of their own, with a closer gap
    [["bands", "dos"]],
    width_ratios=(3, 1),
    margins=("71mm", "6mm", "10mm", "14mm"),
    gap="4mm",
)

labels = {name: vectex.render(source, **theme.vectex()) for name, source in tex.items()}
panels["lattice"].add(lattice_scene(labels), id="lattice-scene")  # labels pinned in 3D, still 8 pt
panels["zone"].add(band_scene(labels), id="band-scene")

for name, plot in (("bands", plot_bands), ("dos", plot_dos)):
    mpl_fig, ax = panels[name].subplots()  # its axes frame is the panel
    plot(ax)
    panels[name].add(mpl_fig, id=f"{name}-plot", fit="axes")

fig.label("a", panels["lattice"].nw)
fig.label("b", panels["zone"].nw)
fig.label("c", (panels["lattice"].x, panels["bands"].y))  # in line with a
fig.label("d", panels["dos"].nw)
fig.save("graphene_bands.pdf")

lattice_scene and band_scene return vecview.Scene objects and the plot functions are plain Matplotlib, all in the example. The grid fixes the panels in millimetres, the plots' frames land exactly on them, the labels pinned into the 3D scenes keep their size however a scene is scaled, so every label prints at the style's 8 pt, and the export refuses to substitute a missing font. The transmon adds a VecWire circuit to the same recipe.

SVG is the canonical output; PDF and PNG are exported through CairoSVG. FigWorks is an assembly layer between plotting code and the final graphic. It does not replace Matplotlib, TeX, Inkscape, or Illustrator.

FigWorks is alpha: the core figure model works and is tested, but the API is still settling and a minor release may change it.

Install

FigWorks is on PyPI and needs Python 3.12 or newer:

python -m pip install figworks

This pulls in Matplotlib, lxml, svg.py, CairoSVG, and VecTeX. Rendering equations with VecTeX also needs a TeX installation with pdflatex and dvisvgm on PATH, and MuPDF's mutool with a current Ghostscript (mupdf-tools on Debian and Ubuntu). VecView and VecWire are optional, both on PyPI:

python -m pip install "vecview>=0.4" "vecwire>=0.3"

Figures are set in TeX Gyre Heros by default, a free Helvetica clone that comes with TeX Live and as fonts-texgyre on Debian and Ubuntu. PDF and PNG export check, through fontconfig, that every font a figure uses is installed and has every glyph it needs, and raise FontError rather than substitute silently.

Agent skill

FigWorks 0.10 and newer bundle a harness-agnostic figure-authoring skill with panel planning, scientific provenance, composition, rendering, and visual review guidance, plus a runnable starter. Installing the Python package makes it available; the explicit command below registers a copy where your agent looks for skills. No checkout or symlink is needed for normal use.

Install for an agent

python -m pip install --upgrade "figworks>=0.10"

# Codex: available across research projects
python -m figworks.skill install ~/.agents/skills/figworks

# Claude Code: available across research projects
python -m figworks.skill install ~/.claude/skills/figworks

Use either destination or both. For another harness, pass its skill directory with figworks as the final folder name. For project-only installation, use a path such as .agents/skills/figworks or .claude/skills/figworks inside the research project. These commands copy the complete bundle and create parents as needed; they do not alter other agent settings.

After upgrading the Python package, rerun each installation with --overwrite:

python -m figworks.skill install ~/.agents/skills/figworks --overwrite

Without this flag, an existing destination is left unchanged. With it, bundled files are replaced, including any local edits to those files; extra files are kept. Symlink destinations are refused even with --overwrite, so updating a normal installation cannot overwrite a development link's source.

Invoke the skill as $figworks in Codex or /figworks in Claude Code. Start a new session if discovery or loaded instructions are stale; Claude Code also supports /reload-skills for discovery. See the official Codex skill locations and Claude Code skill documentation. A harness without skill discovery can read SKILL.md directly from the copied folder. python -m figworks.skill path prints the bundled source directory if only direct access is needed.

Editable installation for development

For contributors, link to the skill in an editable Python checkout. Run from the FigWorks repository root, using your development environment (Linux/macOS):

python -m pip install -e .
figworks_skill="$(python -m figworks.skill path)"

# Choose either or both
mkdir -p "$HOME/.agents/skills"
ln -s "$figworks_skill" "$HOME/.agents/skills/"
mkdir -p "$HOME/.claude/skills"
ln -s "$figworks_skill" "$HOME/.claude/skills/"

Both agents then read the same source files, so edits need no copy or reinstall. Keep the checkout at that path or update the links when moving it. If figworks already exists in a destination, inspect and move the old copy/link aside before switching installation modes; the commands above do not force replacement.

Quick start

Two plots in one Physical Review column, needing only Matplotlib:

import matplotlib.pyplot as plt
import numpy as np

from figworks import Figure
from figworks.matplotlib import theme_rc

plt.rcParams.update(theme_rc("aps"))  # Matplotlib in the figure's face and sizes

fig = Figure(width="86mm", height="42mm", theme="aps")  # one Physical Review column
panels = fig.grid([["power", "phase"]], margins=("5mm", "2mm", "10mm", "13mm"), gap="15mm")

detuning = np.linspace(-4, 4, 200)
response = 1 / (1 + 2j * detuning)
for name, curve, ylabel in (
    ("power", abs(response) ** 2, r"$|S_{21}|^2$"),
    ("phase", np.angle(response), r"$\arg S_{21}$ (rad)"),
):
    mpl_fig, ax = panels[name].subplots()  # its axes frame is exactly the panel
    (line,) = ax.plot(detuning, curve)
    line.set_gid(f"{name}-curve")  # survives into the SVG, for selectors and Inkscape
    ax.set_xlabel(r"$\Delta/\kappa$")
    ax.set_ylabel(ylabel)
    panels[name].add(mpl_fig, id=f"{name}-plot", fit="axes")

fig.label("a", panels["power"].nw)
fig.label("b", panels["phase"].nw)
fig.select("#phase-curve").set_style(stroke="#c2185b")  # edit by id after composing
fig.save("resonance.svg")
fig.save("resonance.pdf")
fig.save("resonance.png", dpi=600)

The two frames are the same size and sit level, however wide their tick labels. Coordinates and sizes accept px, pt, mm, cm, or in; bare numbers are px. The curve ids survive composition, so a selector reaches the phase curve inside its placed plot, and Inkscape finds it by the same id.

For the common case of dropping SVG into existing Matplotlib axes, compose needs no Figure at all:

import figworks
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([0, 1], [0, 1])
svg = figworks.compose({ax: "logo.svg"}, fig=fig)
with open("figure.svg", "w", encoding="utf-8") as output:
    output.write(svg)

What it does

The root package exports Figure, Panel, Anchor, Theme, compose, layout_svgs, display_svg, and FigureCollection. With them you can:

  • create an SVG canvas with physical dimensions and a style: "paper", "presentation", the journal styles "nature", "aps", and "ieee", or your own style.md;
  • divide it into named panels with Figure.grid, or place panels by hand;
  • add rectangular panels with named anchors (panel.nw, panel.center, …);
  • place Matplotlib figures, VecTeX fragments, VecView scenes, VecWire circuits, SVG files, and SVG strings through one call, Panel.add;
  • add native text, panel labels, rectangles, lines, circles, ellipses, polylines, paths, and arrows;
  • reserve placeholders and fill them by id later;
  • lay out many SVGs into a labelled grid;
  • select elements by #id, .class, or tag name, then delete them or set attributes and inline style, which reaches the leaves a source styled itself;
  • save to .svg, .pdf, and .png, byte-identically from run to run, and display figures inline in notebooks;
  • regenerate a whole set of figures from one command with FigureCollection.

Panel.add reads each source's intrinsic size from its viewBox, scales it uniformly, and centres it in the panel; fit="none" keeps the size the source declares instead, so an 8 pt label prints at 8 pt, and align picks the point of the panel it sits on. Placement wraps the source in a group and keeps its ids, prefixing only those that collide with ids already in the figure, so selectors reach inside placed content.

Sources

SVG-producing objects integrate through one method: FigWorks places any object exposing to_svg_document(). VecTeX, VecView, and VecWire implement it without importing FigWorks, and FigWorks has no adapter for any of them.

Plotly plots

Install pip install "figworks[plotly]" and Chrome/Chromium, then pass plotly_to_svg(plot) from figworks.plotly to Panel.add or Figure.add. This produces static SVG; WebGL traces may include raster images. See the Plotly guide for dimensions, fonts, reproducibility, and an example.

VecTeX equations

import vectex

equation = vectex.render(r"\[E = mc^2\]", id_prefix="equation")
panel.add(equation, id="equation-panel")
fig.select("#equation-root").set_attr("color", "navy")  # VecTeX glyphs use currentColor

VecView scenes

import vecview

cam = vecview.OrthographicCamera(azim_deg=35, elev_deg=24, scale=62)
scene = vecview.Scene(cam, pad=6)
slab = vecview.box_faces(center=(0, 0, -0.45), size=(11, 9, 0.9))
scene.faces(10, slab, cull=True, fill="#cfd6e0")

panel.add(scene, id="slab-scene")

Leave the scene's background unset and keep pad small: the scene is scaled to fit its panel, so padding shrinks the drawing.

A scene can also hold content of its own. Scene.plane reserves a rectangle of a world plane and Figure.fill_plane puts a plot in it, foreshortened with the geometry. Scene.slot pins upright content to a world point, and FigWorks keeps that content at its own size, so an 8 pt TeX label stays 8 pt however the scene was scaled:

scene.plane(15, origin=(-4.2, -2.9, 0.01), u_edge=(0, 8.4, 0), v_edge=(5.8, 0, 0), id="plot-plane")

label = vectex.render(r"$\hat{z}$", size_pt=8)
w, h = label.width_px, label.height_px
scene.slot(45, (5.5, 4.5, 0), w, h, content=label.to_svg_py(), align="west", dx=1.6, id="label-z")

panel.add(scene, id="device")
fig.fill_plane("plot-plane", mpl_fig)

fill_plane normalizes content onto the unit square, so shape the plane to the plot's aspect ratio. 3D scenes covers orientation, line weights, and export caveats.

VecWire circuits

A vecwire.Circuit places like any other source, and its component ids and data-component attributes survive placement:

right = fig.panel("schematic", x="120mm", y="8mm", w="40mm", h="56mm")
right.add(circuit, id="transmon-circuit")
fig.select("#JJ")  # a junction drawn with id="JJ"

One style document per publication

---
base: aps            # or nature, ieee, paper, presentation, another style.md
color:
  spin_up: "#d62828"
cycle: [spin_up]
---

# Style guide: what each colour means, which weight is for what ...

A style.md holds the publication's design tokens in its YAML frontmatter and its style guide in prose. FigWorks generates Matplotlib settings from it (theme_rc("style.md")), styles its own elements with it (Figure(..., theme="style.md")), and builds figure sets under it (FigureCollection(style=...)). Built-in bases follow the figure guidelines of Nature, Physical Review, and IEEE. See Styles.

One typography across the suite

In the development checkout, a loaded theme supplies ordinary keyword arguments for each producer, with the correct physical units:

theme = load_theme("aps")
plt.rcParams.update(theme.rc())
plotly_figure.update_layout(template=theme.plotly())
equation = vectex.render(r"$E = mc^2$", **theme.vectex())
scene.text(20, (0, 0, 1), "Device", **theme.vecview_text())
circuit = Circuit(100, 60, **theme.vecwire())
circuit.label("C", (40, 20), **theme.vecwire_label())

Use fit="none" to retain the source's physical type size; fitting a whole source to a smaller panel also shrinks its labels and strokes. The helper for VecWire labels requires its current checkout with font_family support. See the style guide and examples/transmon_figure.py for a complete mixed-source figure.

Aligned Matplotlib panels

panel = fig.panel("a", x="18mm", y="8mm", w="62mm", h="48mm")
mpl_fig, ax = panel.subplots()  # axes frame exactly the panel, at 1:1
ax.plot(x, y)
panel.add(mpl_fig, id="plot-a", fit="axes")

Plots made this way keep their nominal text size, and their axes frames sit exactly on their panels, so frames in a row line up whatever their tick labels.

Matplotlib, both directions

from figworks.matplotlib import connect, insert, mpl_to_svg

svg = mpl_to_svg(mpl_fig)  # Matplotlib -> SVG
connect(ax, "slot", 0.2, 0.2, 0.6, 0.6)  # reserve a placeholder in the axes
result = insert({"slot": panel_fig}, fig=mpl_fig)  # swap in vector SVG by id

Matplotlib exports are made deterministic: FigWorks pins the id salt and drops the export date, which otherwise change on every run.

Placeholders and grids

Create named panels without calculating their coordinates:

fig = Figure(width="180mm", height="110mm")
panels = fig.grid(
    [["device", "device"], ["spectrum", "response"]],
    width_ratios=(3, 2),
    height_ratios=(1, 2),
    margins=("8mm", "6mm", "12mm", "16mm"),  # top, right, bottom, left
    gap=("16mm", "22mm"),  # between rows, between columns
)
panels["device"].add(scene, id="device-scene")
mpl_fig, ax = panels["spectrum"].subplots()
ax.plot(x, y)
panels["spectrum"].add(mpl_fig, id="spectrum-plot", fit="axes")
fig.label("b", panels["spectrum"].nw)

Repeating a name spans a rectangle; None reserves an empty cell. Ratios divide the space remaining after margins and gaps, which keep their physical size when you build a figure at another width. The returned dictionary holds ordinary Panel objects in first-occurrence order. See Grid layout and the complete example.

fig.placeholder("main-slot", x="10mm", y="10mm", w="80mm", h="60mm", label="x")
fig.fill("main-slot", mpl_fig)  # a figure, an SVG file path, or an SVG string
from figworks import layout_svgs

grid = layout_svgs([svg_a, svg_b, svg_c], labels=["a", "b", "c"], outline=True)
grid.save("grid.svg")

Publication preflight

Inspect the assembled figure before exporting:

report = figure.check(target="pdf")
for issue in report.issues:
    print(issue.severity, issue.code, issue.message)
report.raise_for_errors()

The checker reports broken IDs/references, font problems, small placed text and strokes, raster resolution, external resources, and conservative page overflow. report.unchecked lists coverage limits for CSS, complex bounds, and other features that need visual inspection. A clean report is not a certification of arbitrary SVG. See the preflight guide.

Known limitations

A gradient-filled <mask> does not survive CairoSVG and vanishes from PDF and PNG exports without a warning.

Examples

The gallery holds journal figures from across the sciences, each one self-contained script. They need VecView and TeX; the transmon also needs VecWire, and the triode needs VecView 0.5 or later and no TeX. Run from the repository root:

python examples/transmon_figure.py      # superconducting qubits
python examples/graphene_bands.py       # condensed matter
python examples/microring_resonator.py  # photonics
python examples/optical_tweezers.py     # biophysics
python examples/hodgkin_huxley.py       # neuroscience
python examples/exoplanet_transit.py    # astrophysics
python examples/energy_landscape.py     # chemistry
python examples/climate_energy_balance.py # climate science
python examples/production_network.py    # economics
python examples/vacuum_triode.py         # electronics, in a vintage style
python examples/gallery.py              # all of them, with a preflight report

Two scripts show workflows rather than figures, with core dependencies only:

python examples/publication_preflight.py # a deliberately flawed figure and its report
python examples/thesis_plots.py --all    # a figure collection with a shared style

Each example writes its figures into examples/out/.

The suite

FigWorks is the composition layer of four projects developed together, each independently useful:

Project Produces Maturity
FigWorks composed, exported multi-panel figures alpha: core API still settling
VecTeX editable TeX equations as SVG fragments beta: on PyPI, API settled enough to build on
VecView layered 3D schematics as SVG documents alpha: on PyPI, API may change before 1.0
VecWire editable circuit schematics as SVG documents alpha: on PyPI, API may change before 1.0

All four emit vector SVG with stable ids and byte-identical output for identical input, so a figure can be regenerated from code, diffed in version control, and still hand-tuned in Inkscape. All four are pre-1.0 and make no backward-compatibility promise; deterministic output is a shared design contract within a fixed rendering environment. Pin the producer, TeX/converter, browser, and font versions when archiving a build. Manual SVG edits remain editable artifacts; they are not automatically merged into regenerated output.

The dependency edges are uneven by design: VecTeX is a runtime requirement, VecView and VecWire are optional, and none of the three depends on FigWorks.

Development

python -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"
ruff format --check .
ruff check .
ty check
pytest

Tests for VecView and VecWire skip when those packages are not installed, and tests that render VecTeX skip without pdflatex and dvisvgm. Rendering tests need TeX Gyre Heros, DejaVu Sans, and fontconfig's command-line tools (Debian/Ubuntu: fonts-texgyre fonts-dejavu-core fontconfig).

Documentation

The docs in docs/ are built with Zensical:

zensical serve    # preview at http://localhost:8000
zensical build    # static build into site/

License

MIT

Metadata

Release files for figworks 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for figworks 0.11.0
File Size Uploaded Provenance Actions
figworks-0.11.0.tar.gz 124.6 kB With provenance Details for figworks-0.11.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for figworks 0.11.0
File Interpreter ABI Platform Actions
figworks-0.11.0-py3-none-any.whl Python 3 none any Details for figworks-0.11.0-py3-none-any.whl

Total release size: 215.1 kB

Release files / figworks-0.11.0.tar.gz

Download URL figworks-0.11.0.tar.gz
Size 124.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c21271691021976ca6748c8a76d13e63600ecae519ea456288224d074f791a2f
BLAKE2b-256 checksum
How to use checksums
009d5ef38c5bc70650849d84d74269f269d1b5ae3fd2f4724223fe299c248ada
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / figworks-0.11.0-py3-none-any.whl

Download URL figworks-0.11.0-py3-none-any.whl
Size 90.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a1cae00959a44d35b599c214f336a425ed4e016920d211e658059130c28948f
BLAKE2b-256 checksum
How to use checksums
739be9c656fa820b007a41d2def55565d5387faae8d1d5cd80609d006d810d04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for figworks 0.11.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for figworks-0.11.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page