Skip to main content

Reproducible matplotlib wrapper with mm-precision layouts

Project description

FigRecipe (scitex-plt)

SciTeX

Reproducible scientific figures as first-class objects

PyPI version Documentation Tests License: AGPL-3.0

Full Documentation · pip install figrecipe


Reproducible, editable, publication-ready scientific figures. Part of SciTeX.

SciTeX users: pip install scitex[plt] includes FigRecipe. scitex.plt delegates to figrecipe — they share the same API.

Overview

FigRecipe treats recipe, data, and style as first-class attributes of every figure. This enables data governance and style editing without losing scientific rigor.

FigRecipe: Reproducible Scientific Figures

Styling

FigRecipe provides millimeter-precise control over every visual element. The SCITEX style preset is applied by default, producing publication-ready figures with standard matplotlib plotting.

SCITEX Style Anatomy

Millimeter-based Layout
fig, ax = fr.subplots(
    axes_width_mm=60,
    axes_height_mm=40,
    margin_left_mm=15,
)
Style Presets
fr.load_style("SCITEX")       # Publication defaults
fr.load_style("SCITEX_DARK")  # Dark theme
fr.load_style("MATPLOTLIB")   # Pure Matplotlib

GUI Editor

For precise adjustments, GUI editor is available.

FigRecipe GUI Editor

Migration from Matplotlib

Matplotlib-compatibility

FigRecipe is a drop-in replacement for matplotlib — just change your import:

# Before
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(x, y)
plt.savefig("fig.png")

# After
import figrecipe as fr
fig, ax = fr.subplots()
ax.plot(x, y, id="my_trace")
fr.save(fig, "fig.png")  # → fig.png + fig.yaml + fig_data/

Systematic Migration

scitex-linter detects and auto-fixes matplotlib patterns into mm-based FigRecipe equivalents (check, format, python). It also works as a pre-commit hook, ensuring AI agents follow FigRecipe conventions.

Schematic Diagrams

Left-to-right schematic

Create publication-quality box-and-arrow schematics with mm-based coordinates:

s = fr.Schematic(title="EEG Analysis Pipeline", width_mm=350, height_mm=100)
s.add_box("raw", "Raw EEG", subtitle="64 ch", emphasis="muted")
s.add_box("filter", "Bandpass Filter", subtitle="0.5-45 Hz", emphasis="primary")
s.add_box("ica", "ICA", subtitle="Artifact removal", emphasis="primary")
s.add_arrow("raw", "filter")
s.add_arrow("filter", "ica")
s.auto_layout(layout="lr", gap_mm=15)

fig, ax = fr.subplots()
ax.schematic(s, id="pipeline")
fr.save(fig, "pipeline.png")

Three Interfaces

🐍 Python API

Create and save — standard matplotlib API with auto-recording:

import figrecipe as fr
import numpy as np

fig, ax = fr.subplots()
ax.plot(np.sin(np.linspace(0, 10, 100)), id="sine")
fr.save(fig, "figure.png")  # Saves + validates pixel-identical reproduction

Output:

figure.png                # Publication-ready image
figure.yaml               # Reproducible recipe (validated on save)
figure_data/
  sine.csv                # Plot data (one CSV per trace)

Save / Load Formats — from recipe or bundle:

fr.save(fig, "fig.png")     # fig.png + fig.yaml
fr.save(fig, "fig.zip")     # self-contained zip bundle
fr.load("fig.png")          # reload from any format
Format Save Load
PNG / PDF / SVG
YAML
Directory / ZIP

Reproduce and edit — from recipe or bundle:

fig, ax = fr.reproduce("figure.yaml")
fr.gui(fig)  # Launch visual editor (at http://127.0.0.1:5050 by default)

Compose — multi-panel figures:

fr.compose(
    sources=["panel_a.yaml", "panel_b.yaml"],
    output_path="composed.png",
    layout="horizontal",
)

Composed multi-panel figure

Statistics — significance brackets:

ax.add_stat_annotation(x1=0, x2=1, p_value=0.01, style="stars")

Full API reference

🖥️ CLI Commands
figrecipe --help-recursive            # Show all commands
figrecipe reproduce fig.yaml          # Recreate figure from recipe
figrecipe gui figure.png              # Launch visual editor
figrecipe validate fig.yaml           # Verify pixel-identical reproduction
figrecipe extract fig.yaml            # Extract plotted data as CSV
figrecipe compose a.yaml b.yaml       # Compose multi-panel figure
figrecipe crop figure.png             # Auto-crop whitespace
figrecipe info fig.yaml               # Show recipe metadata

Full CLI reference

🔧 MCP Server — for AI Agents

AI agents can create, compose, and reproduce publication-ready figures autonomously.

Tool Description
plot Create figure from declarative YAML spec
reproduce Recreate figure from recipe
compose Combine panels into multi-panel layout
crop Auto-crop whitespace
info Inspect recipe metadata
validate Verify reproduction fidelity
# Install to Claude Code
figrecipe mcp install

Full MCP specification

47 matplotlib plot types supported

Category Plot Types
Line & Curve plot, step, fill, fill_between, fill_betweenx, errorbar, stackplot, stairs
Scatter & Points scatter
Bar & Categorical bar, barh
Distribution hist, hist2d, boxplot, violinplot, ecdf
2D Image & Matrix imshow, matshow, pcolor, pcolormesh, hexbin, spy
Contour & Surface contour, contourf, tricontour, tricontourf, tripcolor, triplot
Spectral & Signal specgram, psd, csd, cohere, angle_spectrum, magnitude_spectrum, phase_spectrum, acorr, xcorr
Vector & Flow quiver, barbs, streamplot
Special pie, stem, eventplot, loglog, semilogx, semilogy, graph

SciTeX
AGPL-3.0 · ywatanabe@scitex.ai

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

figrecipe-0.22.0.tar.gz (2.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

figrecipe-0.22.0-py3-none-any.whl (766.9 kB view details)

Uploaded Python 3

File details

Details for the file figrecipe-0.22.0.tar.gz.

File metadata

  • Download URL: figrecipe-0.22.0.tar.gz
  • Upload date:
  • Size: 2.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc1

File hashes

Hashes for figrecipe-0.22.0.tar.gz
Algorithm Hash digest
SHA256 07549443f8de723501ce0bbbf1896701d0f20198d0a9748c936dd400d58a3a33
MD5 2cc8f430d43131364d513591887b2cc1
BLAKE2b-256 0a12f6517648e2a35eb49fe95c82fc8da4323b4522edf379ef2a3635bd710c21

See more details on using hashes here.

File details

Details for the file figrecipe-0.22.0-py3-none-any.whl.

File metadata

  • Download URL: figrecipe-0.22.0-py3-none-any.whl
  • Upload date:
  • Size: 766.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc1

File hashes

Hashes for figrecipe-0.22.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bfe40db90050d8d8b6bb2176bc83bc631f4243c08cc5fb00c70ff1bc570ac130
MD5 9480dd00225f85f35601dcd352b90870
BLAKE2b-256 666c4e79d57a4c27ae1b341265621364d2e16ba14d36f7da22bba174b5c2370c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page