Skip to main content

Minimal pgfplots wrapper for marimo notebooks

Project description

pypgfplots

Minimal Python wrapper that renders pgfplots figures as high-quality PNG inside marimo notebooks. Figures are identical to what you would include in a LaTeX paper or slide deck — because they are LaTeX.

Requires a working LaTeX installation with pdflatex on $PATH, plus a PDF→PNG converter — install one of:

brew install poppler       # provides pdftoppm (recommended)
brew install mupdf-tools   # provides mutool
brew install imagemagick   # provides convert

Ghostscript (gs) is also accepted if already on $PATH.


Installation

From GitHub with uv (recommended)

uv add git+https://github.com/bjoseru/pypgfplots

Inside a marimo notebook

Add a cell at the top:

import subprocess
subprocess.run(["uv", "pip", "install", "git+https://github.com/bjoseru/pypgfplots"])

Or use marimo's package manager sidebar (requires uv backend).

Plain pip

pip install git+https://github.com/bjoseru/pypgfplots

Quick start

from pypgfplots import Axis

a = Axis(title="Parabola", xlabel=r"$x$", ylabel=r"$f(x)$")
a.addplot(r"x^2", color="red", domain="-2:2", samples=100)
a  # displays as PNG in marimo

Combine two axes side by side:

a = Axis(title="Left")
a.addplot(r"sin(deg(x))", domain="0:6.28")

b = Axis(title="Right", axis_lines="left")
b.addplot(r"cos(deg(x))", domain="0:6.28")

a + b  # renders both in one tikzpicture

Coordinate data

coords = " ".join(f"({x},{x**2})" for x in range(6))
a = Axis()
a.addplot(coords, _type="coordinates", mark="*", color="blue")
a

Table data

a = Axis()
a.addplot("data.csv", _type="table", col_sep="comma", x="time", y="value")
a

3-D plots

a = Axis()
a.addplot3(r"x^2 + y^2", domain="-2:2", samples=30)
a

Global settings

from pypgfplots import pgfplotset, preamble, classoptions

pgfplotset(compat="1.18")
preamble(r"\usepackage{amsmath}")
classoptions("border=5pt")

Export

a.save_pdf("figure.pdf")   # compile and write PDF
a.save_tex("figure.tex")   # write LaTeX source (no compilation)
src = a.latex()             # full standalone source as string
log = a.compile_log()       # pdflatex output of last run

Development

Clone the repo and install in editable mode:

git clone https://github.com/bjoseru/pypgfplots
cd pypgfplots
uv pip install -e .

Run the tests:

uv run --with pytest pytest

Tests that require pdflatex and a PDF→PNG converter are skipped automatically if those tools are not on $PATH. To run only the pure-Python unit tests:

uv run --with pytest pytest tests/test_core.py tests/test_options.py

Pipeline

Display:  Python API  →  .tex  →  pdflatex  →  PDF  →  pdftoppm  →  PNG  →  marimo
PDF:      Python API  →  .tex  →  pdflatex  →  PDF

The PNG is delivered via _repr_html_() and is therefore also usable in Jupyter.


License

MIT — see 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

pypgfplots-0.1.8.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

pypgfplots-0.1.8-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file pypgfplots-0.1.8.tar.gz.

File metadata

  • Download URL: pypgfplots-0.1.8.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pypgfplots-0.1.8.tar.gz
Algorithm Hash digest
SHA256 a9c8e6d24db2884064ac8a7034a513d901e46d107e2b5d4a88af66ecbc9295e5
MD5 59ccb41c71d9243eec0d623e65fb69cc
BLAKE2b-256 ae7ee3e065f9acf3dd23efe5cf3e1860a05259f6e5fa4b0efe9a75fe7a720b60

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgfplots-0.1.8.tar.gz:

Publisher: publish.yml on bjoseru/pypgfplots

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgfplots-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: pypgfplots-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pypgfplots-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 53d6586555a6aac4f653abd4edf4267963684f3f6925efb042e0dc51d5c3b85e
MD5 1af5f9771e20478fb1236596787632fa
BLAKE2b-256 74a7556fe62ae0e9e69eae09732590d664f621583a0fd17159c8e6aa80569199

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgfplots-0.1.8-py3-none-any.whl:

Publisher: publish.yml on bjoseru/pypgfplots

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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