Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

plothero

Plotly-compatible plotting for heavy signals — Rust core, Python API.

plothero is not a replacement for Plotly. It's a drop-in for the specific case where your traces are too large for Plotly.js to pan and zoom smoothly. For everything else, use Plotly directly.

plothero.graph_objects mirrors plotly.graph_objects closely enough that most Figure/Scatter code works after just swapping the import. The whole public API is also available from the top-level package, so the examples use import plothero as ph. The difference: traces above a size threshold (default 5 000 points) are automatically decimated with a Rust-accelerated LTTB, Min/Max, or M4 algorithm before being handed to Plotly.js, so a 5-million-point signal still pans and zooms smoothly in the browser.


Requirements

  • Python ≥ 3.9

Building from source additionally requires the Rust toolchain (rustc + cargo) and maturin — not needed when installing prebuilt wheels via pip install plothero. Without a compiled extension, the package still works via pure-Python fallback implementations with identical output. LTTB is about 60× slower without Rust; MinMax and M4 run at about the same speed.

Install Rust and Cargo with rustup:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
rustc --version   # sanity check

macOS users can alternatively run brew install rust. If maturin develop fails with rustc, the rust compiler, is not installed or not in PATH, Rust hasn't been installed yet, or the current shell hasn't picked up ~/.cargo/env — install it (or re-run source "$HOME/.cargo/env") and try again.

could not amend shell profile: '~/.bash_profile': ... Permission denied — the rustup installer failed to add the cargo env line to ~/.bash_profile because that file isn't owned by you (or isn't writable). Rust itself is still installed correctly; you just need cargo env sourced from a profile file your shell actually reads. If you use zsh (the macOS default), add it to ~/.zprofile instead:

echo '. "$HOME/.cargo/env"' >> ~/.zprofile

Open a new terminal (or source ~/.zprofile) and rustc --version should work.


Installation

pip install plothero

Prebuilt wheels ship the compiled Rust extension, so no Rust toolchain is needed on the machine installing the package. Each wheel targets the stable Python ABI (abi3), so one wheel per platform covers Python 3.9 and newer:

Platform Architectures
Linux (manylinux) x86_64, aarch64
macOS x86_64 (Intel), arm64 (Apple Silicon)
Windows x64

On any other platform (for example musl-based Linux such as Alpine, or Windows on ARM), pip falls back to the source distribution and compiles the extension, which requires a Rust toolchain. Confirm the compiled extension is active with:

python -c "import plothero as ph; print(ph.rust_available())"  # True

Local development

See the Development section below for the full setup, build, and test workflow. Short version:

python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
maturin develop --release
pytest

Quick start

import numpy as np
import plothero as ph

t = np.linspace(0, 60, 5_000_000)  # 5M points
y = np.sin(2 * np.pi * 1.2 * t) + 0.1 * np.random.randn(len(t))

fig = ph.Figure()
fig.add_trace(ph.Scatter(x=t, y=y, mode="lines", name="PPG",
                          line=dict(color="#e41a1c", width=1)))
fig.update_layout(title="PPG Signal", xaxis_title="Time (s)", yaxis_title="Amplitude")
fig.show()               # opens in the default browser
html = fig.to_html()     # HTML string, for notebooks / dashboards

x accepts numeric arrays, datetime64, or a pandas DatetimeIndex — datetime handling is automatic, same as real Plotly.

The same figure built with real Plotly uses the same calls, only under plotly.graph_objects instead of ph. Rendering 5M raw points client-side is slow to pan/zoom (or crashes the tab entirely) without plothero's downsampling:

import numpy as np
import plotly.graph_objects as go   # <- the only line that changes

t = np.linspace(0, 60, 5_000_000)  # 5M points
y = np.sin(2 * np.pi * 1.2 * t) + 0.1 * np.random.randn(len(t))

fig = go.Figure()
fig.add_trace(go.Scatter(x=t, y=y, mode="lines", name="PPG",
                          line=dict(color="#e41a1c", width=1)))
fig.update_layout(title="PPG Signal", xaxis_title="Time (s)", yaxis_title="Amplitude")
fig.show()               # opens in the default browser
html = fig.to_html()     # HTML string, for notebooks / dashboards

Walkthrough

examples/walkthrough/ in the repository is a series of scripts that go through every feature on a real signal: the UCI household power dataset, about 2 million samples per channel with timestamps. It covers building the Rust extension, the downsampling methods, a Rust vs pure-Python benchmark, subplots, bar charts, heatmaps, export, and interactive zoom.

pip install -e ".[dev,examples]"   # adds pandas and plotly
maturin develop --release
python examples/walkthrough/01_check_install.py
python examples/walkthrough/02_overview.py   # and so on, up to 10

The dataset (about 20 MB) is downloaded on first run and cached in examples/walkthrough/data/. See examples/walkthrough/README.md for the full list.


API reference

plothero.graph_objects.Figure

Mirrors plotly.graph_objects.Figure:

Method Description
add_trace(trace, row=, col=) / add_traces([...]) Add one or more Scatter/Bar/Heatmap traces (or plain dicts). row/col (1-indexed) target a specific subplot panel — see below. Returns self.
add_scatter(row=, col=, **kwargs) Shortcut for add_trace(Scatter(**kwargs), row=row, col=col).
add_bar(row=, col=, **kwargs) Shortcut for add_trace(Bar(**kwargs), row=row, col=col).
add_heatmap(row=, col=, **kwargs) Shortcut for add_trace(Heatmap(**kwargs), row=row, col=col).
update_layout(**kwargs) Update layout — supports Plotly's magic-underscore kwargs (xaxis_title=, line_color=, ...).
update_xaxes(row=, col=, **kwargs) / update_yaxes(row=, col=, **kwargs) Update axis properties — every axis by default, or one subplot panel via row=/col=.
.data / .layout Read-only access to traces / layout.
to_dict() / to_json() Plotly JSON spec.
to_html(full_html, include_plotlyjs) HTML string ("cdn" / "inline" / False).
write_html(path) Write the figure to an HTML file.
show(*, detached=True) Serve the figure from a local HTTP server (http://127.0.0.1:<port>) and open it in the default browser. By default the server runs in a separate background process, so your script can exit while the figure stays interactive. Pass detached=False to serve from the current process instead.
to_plotly_figure() Convert to a real plotly.graph_objects.Figure (requires pip install plotly).

Figure also implements _repr_html_, so it renders inline in Jupyter.

show() hands the figure to a separate viewer process and returns immediately, so a script that processes data and then plots it finishes normally while the figure stays open, like a MATLAB figure. Zooming into a decimated trace keeps re-fetching full-resolution data from that viewer process on every pan/zoom. The viewer exits on its own shortly after you close the last browser tab showing the figure. See Downsampling → dynamic re-downsampling on zoom.

import numpy as np
import plothero as ph

t = np.linspace(0, 60, 5_000_000)
y = np.sin(2 * np.pi * 1.2 * t) + 0.1 * np.random.randn(len(t))

fig = ph.Figure()
fig.add_trace(ph.Scatter(x=t, y=y, name="signal"))
fig.show()                  # returns right away; the script can exit
# fig.show(detached=False)  # serve from this process; blocks exit until Ctrl+C

plothero.graph_objects.Scatter

Accepts the same keywords as plotly.graph_objects.Scatter — x, y, mode, name, line, marker, opacity, text, fill, hovertemplate, magic-underscore shortcuts (line_color=, marker_size=, ...). Anything not explicitly modeled is passed straight through to the Plotly.js trace spec.

Two extra keywords control the Rust-accelerated downsampling (not part of real Plotly, additive only):

Parameter Type Default Description
downsample_threshold int 5000 Downsample when len(x) > threshold.
downsample_method DownsampleMethod MINMAX MINMAX (preserves peaks/troughs — best for biomedical signals), M4 (like MINMAX but also keeps each bucket's first/last sample, at up to 2x the point cost), LTTB (best visual fidelity for smooth signals), or NONE.
import plothero as ph

ph.Scatter(x=t, y=y, mode="lines", downsample_method=ph.DownsampleMethod.LTTB,
           downsample_threshold=2_000)

plothero.graph_objects.Bar / plothero.graph_objects.Heatmap

Accept the same keywords as plotly.graph_objects.Bar / plotly.graph_objects.Heatmap — x/y/name/orientation/marker for Bar, z/x/y/name/colorscale for Heatmap — plus magic-underscore shortcuts and passthrough of anything not explicitly modeled, same as Scatter. No downsampling (categorical/gridded data, not dense signals).

fig.add_bar(x=["a", "b", "c"], y=[10, 20, 15], marker_color="#377eb8")
fig.add_heatmap(z=[[1, 20, 30], [20, 1, 60], [30, 60, 1]], colorscale="Viridis")

plothero.subplots.make_subplots

Mirrors plotly.subplots.make_subplots — builds a Figure pre-populated with a grid of axes; row/col (1-indexed, row 1 = top) route traces and axis updates to a specific panel:

import plothero as ph

fig = ph.make_subplots(rows=1, cols=2, subplot_titles=("Raw", "Filtered"))
fig.add_trace(ph.Scatter(x=t, y=raw, name="raw"), row=1, col=1)
fig.add_trace(ph.Scatter(x=t, y=filtered, name="filtered"), row=1, col=2)
fig.update_xaxes(title="Time (s)", row=1, col=1)
fig.show()

Supports shared_xaxes/shared_yaxes, horizontal_spacing/vertical_spacing, column_widths/row_heights, and subplot_titles, same as real Plotly.

Standalone downsampling functions

import numpy as np
import plothero as ph

t = np.linspace(0, 10, 1_000_000, dtype=np.float64)
y = np.sin(t)

t_small, y_small = ph.lttb_downsample(t, y, threshold=2_000)
t_small, y_small = ph.minmax_downsample(t, y, n_out=2_000)
t_small, y_small = ph.m4_downsample(t, y, n_out=2_000)

Migrating from plotly

-import plotly.graph_objects as go
+import plothero.graph_objects as go

The go alias keeps existing Plotly code unchanged. For new code, prefer import plothero as ph, which exposes the same objects (ph.Figure, ph.Scatter, ph.make_subplots, ...).

Trace/layout construction, add_trace, update_layout, to_html, show, make_subplots, and Jupyter rendering all behave the same way. Scatter, Bar, and Heatmap are implemented so far (Scatter covers line/marker plots and time series — datetime x "just works"). Multi-trace figures with plot_bgcolor, legend, margin, custom hovertemplate, etc. are supported via passthrough kwargs.


Architecture

plothero/
├── src/lib.rs              Rust: lttb_downsample, minmax_downsample, m4_downsample (PyO3 + numpy)
├── Cargo.toml               Rust package (pyo3 = "0.21", numpy = "0.21")
├── pyproject.toml           Build: maturin >= 1.4
└── plothero/
    ├── __init__.py          Re-exports the public API
    ├── graph_objects.py     Plotly-compatible Figure / Scatter / Bar / Heatmap / Layout
    ├── subplots.py          Plotly-compatible make_subplots (multi-panel figures)
    └── downsample.py        Rust dispatch + pure-Python fallback + DownsampleMethod

The Rust module is compiled as plothero._core and used transparently by Scatter.downsample(). If the compiled extension is absent, the pure-Python fallback in downsample.py is used automatically — same results, slower on large arrays. Check which backend is active with:

import plothero as ph
print(ph.rust_available())

Development

Everything below assumes you've cloned the repo and are working from its root.

1. Set up a virtual environment

python3 -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate

2. Install the Rust toolchain (one-time)

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
rustc --version   # sanity check

3. Install dev dependencies and build the extension

pip install -e ".[dev]"     # maturin, pytest, pandas, plotly
maturin develop              # debug build, fast to compile, slower at runtime
# or: maturin develop --release   # optimized build, use this for benchmarking

maturin develop compiles src/lib.rs and installs the resulting extension as plothero._core directly into your active virtual environment — no pip install round-trip needed. Confirm it worked:

python -c "import plothero as ph; print(ph.rust_available())"  # True

If you skip steps 2–3, plothero still imports and works correctly — it silently uses the pure-Python fallback in downsample.py instead. That's fine for working on graph_objects.py, but you'll want the Rust extension built when touching src/lib.rs or benchmarking large signals.

4. Rebuild after editing Rust code

Re-run maturin develop (or --release) any time you change src/lib.rs — Python code changes under plothero/ take effect immediately, no rebuild needed.

5. Run the tests

pytest              # run the full suite
pytest -v            # verbose, one line per test
pytest tests/test_downsample.py   # just the downsampling algorithms
pytest -k datetime   # only tests matching "datetime"

The test suite (tests/) covers both layers:

  • tests/test_downsample.py — LTTB, Min/Max, and M4 downsampling correctness (shape preservation, peak/trough retention, edge cases). These tests run against whichever backend is active (Rust if built, pure-Python otherwise), so run them both before and after maturin develop if you change src/lib.rs.
  • tests/test_graph_objects.py — the Plotly-compatible API surface: Scatter/Bar/Heatmap/Layout/Figure construction, magic-underscore expansion, datetime handling, HTML/JSON output.
  • tests/test_subplots.py — make_subplots grid/domain math and its integration with Figure.add_trace/update_xaxes/update_yaxes.

6. Releasing

Publishing a GitHub release whose tag is v plus the version in Cargo.toml builds and tests the wheels, publishes them to PyPI, and attaches them to the release. See Releasing in the docs for the full steps and the one-time PyPI setup.


Roadmap

  • More trace types (Box, Pie, Histogram) beyond Scatter, Bar, Heatmap
  • Desktop GUI rendering target (Qt/GTK), alongside the current browser/Jupyter target

Metadata

Release files for plothero 0.3.0b1

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

Source distribution (sdist)

Source distribution for plothero 0.3.0b1
File Size Uploaded Provenance Actions
plothero-0.3.0b1.tar.gz 115.3 kB Without provenance Details for plothero-0.3.0b1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for plothero 0.3.0b1
File Actions
plothero-0.3.0b1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for plothero-0.3.0b1-cp39-abi3-win_amd64.whl
plothero-0.3.0b1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for plothero-0.3.0b1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
plothero-0.3.0b1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for plothero-0.3.0b1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
plothero-0.3.0b1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for plothero-0.3.0b1-cp39-abi3-macosx_11_0_arm64.whl
plothero-0.3.0b1-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for plothero-0.3.0b1-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 1.4 MB

Release files / plothero-0.3.0b1.tar.gz

Download URL plothero-0.3.0b1.tar.gz
Size 115.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a0af9dffb2aa03c67e70e8ac03868039704ccdde80ce1c21a2c0ef5deb955497
BLAKE2b-256 checksum
How to use checksums
abcbb73c9659336aa029b06b71ad83a31bd67004297afcf9dcc81031ebd6fb83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / plothero-0.3.0b1-cp39-abi3-win_amd64.whl

Download URL plothero-0.3.0b1-cp39-abi3-win_amd64.whl
Size 177.4 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
1e5e2c4f9f2d4e29a2d17ed7b482bcc0307dcd046254a44080f800dc25dc5fe6
BLAKE2b-256 checksum
How to use checksums
ef5582d2de2167f80a4f0135c32c99d27e1a9d8505fa348ab5ffc79593a0685a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / plothero-0.3.0b1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL plothero-0.3.0b1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 275.9 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
86afadb45ac11b34f0850d37c3832b8d23390036ac1bd74eb0e2ab9c888bc5b4
BLAKE2b-256 checksum
How to use checksums
97356a2550d69691c5b66671dc63b9612e4e6acf25d9693e53c5cff5ec4b1c39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / plothero-0.3.0b1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL plothero-0.3.0b1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 275.8 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
28ba9eab760e2196e3902663030f48083d9941518fd3a15c0fb9636ddbd45875
BLAKE2b-256 checksum
How to use checksums
0ffb686ef292343276ebb09cd62f1ff632c5de60f02010d9eba17444fb372393
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / plothero-0.3.0b1-cp39-abi3-macosx_11_0_arm64.whl

Download URL plothero-0.3.0b1-cp39-abi3-macosx_11_0_arm64.whl
Size 257.1 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0632f04f37f5a62b314f989f398a4d9904c154b82452ae37a9da2a86add7f86f
BLAKE2b-256 checksum
How to use checksums
7d065592618fe33fcf672a2607b86009ba0cdee1b204ef3659aebdcfe6514cdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / plothero-0.3.0b1-cp39-abi3-macosx_10_12_x86_64.whl

Download URL plothero-0.3.0b1-cp39-abi3-macosx_10_12_x86_64.whl
Size 266.2 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
7967fee3d1e4a97d3bf8898700a75db1f9e446c3c15e91ca854646034e016af9
BLAKE2b-256 checksum
How to use checksums
95e714715054cbb2e78e972f7381d0c7fa668753d5db5d82386e14bda6638ada
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for plothero 0.3.0b1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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