Skip to main content

JSON-driven orchestration for building and concatenating paper figures.

Project description

paperfig: JSON‑driven figure orchestrator

paperfig is a small library for building per-figure PDFs from a JSON spec and combining them into a single figures.pdf. The JSON file can mix data and rendering functions, so you can flexibly compose plots and layouts. This makes it handy for generating figures for papers. You provide the renderers (Python functions that draw and save fig{index}.pdf), while paperfig takes care of JSON parsing, dispatching, multi-panel layouts, and concatenation.

Key features

  • Simple JSON spec → figures
  • Use your own renderers; paperfig only orchestrates
  • Supports both simple figures and multi‑panel grids
  • Concatenates everything into a single figures.pdf
  • Extensible: register functions, import "module:function", or use entry points

Install

  • Library only: pip install paperfig
  • With example dependencies: pip install "paperfig[examples]"

Quick start (run the bundled example)

  • Clone the source repository
git clone https://github.com/sekika/paperfig.git
  • Change into the examples directory and run the script:
cd paperfig/docs/examples
python fig.py
  • Outputs:
    • docs/examples/fig/fig1.pdf, fig2.pdf, fig3a.pdf … fig3d.pdf
    • docs/examples/fig/fig3.pdf (2x2 multi panel)
    • docs/examples/fig/figures.pdf (all pages concatenated)

CLI

  • Build: paperfig build path/to/fig.json -d out -o figures.pdf
  • Validate only: paperfig validate path/to/fig.json
  • List figures: paperfig list path/to/fig.json

Minimal API example

  • Define a renderer that writes fig{index}.pdf into fig_dir. Register and build.
from paperfig.figure import Fig
import matplotlib.pyplot as plt

def render_hello(index, data, verbose=1):
    fig, ax = plt.subplots()
    ax.text(0.5, 0.5, f"Hello {index}", ha="center", va="center")
    plt.savefig(f"out/fig{index}.pdf"); plt.close(fig)

fig = Fig("fig.json")
fig.fig_dir = "out"
fig.function = {"hello": render_hello}
fig.create_pdf()

JSON spec example (with multi)

{
  "1": { "type": "hello" },
  "2": { "type": "hello" },
  "3": {
    "type": "multi",
    "row": 1,
    "column": 2,
    "figures": {
      "3a": { "type": "hello" },
      "3b": { "type": "hello" }
    }
  }
}

Extensibility

  • Register a renderer in code: fig.function["name"] = callable
  • Refer to a renderer by string: "module:function" in JSON type
  • Plugin system: packages can expose entry points under paperfig.renderers

Documentation

License

  • MIT License

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

paperfig-0.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

paperfig-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file paperfig-0.1.0.tar.gz.

File metadata

  • Download URL: paperfig-0.1.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for paperfig-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ee181bd57b899b8dd5e056a0f24842fc22d1df3edde57c5df590942fc2e8ef0e
MD5 e5e025f71a40cd947861547fdf1bd977
BLAKE2b-256 101b9c50cc53195d45e71e04344781170bcc59895d05b1b11f558dfe209904f6

See more details on using hashes here.

File details

Details for the file paperfig-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: paperfig-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for paperfig-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2aa89b15bafc52412104d0b40e245e98b2defd8d512ecfa2d77b9559fbe27d4
MD5 7c58b2cda268ed3b62bfccbdca10819c
BLAKE2b-256 498b27db6399985f4ba1f06103ca9c9d3a3ec92fa4edbb9c6e137f4fadc21cd4

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