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.2.0.tar.gz (6.1 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.2.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: paperfig-0.2.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for paperfig-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ac49472d74456f20131cd9e43b97ea681323ffba67816aa31a5c286a44527cd9
MD5 7b4a508208739ff641f5721a6389208d
BLAKE2b-256 b43107266eb317f7bb5cbfc983182c39640e80eecf97add752fe7f6d3cdcdeee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: paperfig-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for paperfig-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9145eadd2b74eff108b19a4c8dbec596126ab112d3aa31c15fffd1cf9453fab0
MD5 af188af34acd8d38f7c1640a2499cf59
BLAKE2b-256 eaffaa2703817fb5a817b12f043f5d66eb977cc5de95819610f347eaeff13519

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