photonviz
GPU-accelerated (WebGL2) charts for Jupyter, JupyterLab and Google Colab.
· 📖 Docs
· ▶ Live demo
The Python bridge to Photon. NumPy arrays and torch tensors cross to the browser as binary buffers, so a million points still pan and zoom at 60fps inside a notebook cell — no image round-trip, no JSON blow-up.
pip install photonviz
Nothing else to install: the widget ships one self-contained ESM bundle, so there
is no CDN fetch, no jupyter labextension install, and no separate JS package.
Real capture from JupyterLab — 200k points, interactive: wheel to zoom, drag to pan, hover for a tooltip.
Quick start
import numpy as np
import photonviz as pv
x = np.linspace(0, 10, 200_000)
pv.line(x, np.sin(x) + 0.3 * np.sin(x * 7), name="signal", plot={"theme": "dark", "legend": True})
Charts chain, and the last expression in a cell renders itself:
(pv.Plot(theme="dark", title="Two series", legend=True)
.line(x, np.sin(x), name="sin", color="#60a5fa")
.line(x, np.cos(x), name="cos", color="#f472b6", dash=[6, 4])
.hline(0, color="#64748b"))
Every keyword maps 1:1 onto the TypeScript options,
so the JS reference applies verbatim — color, width, step, colorBy,
yAxis, renderType, and so on.
Google Colab
Run once per session, then use photonviz normally:
from google.colab import output
output.enable_custom_widget_manager()
What you can draw
pv.scatter(x, y, sizes=area, colors=hex_list) # bubble chart
pv.histogram(samples, bins=40)
pv.heatmap(z, cols, rows, extent={"x": [0, 1], "y": [0, 1]}, colormap="magma")
pv.candlestick(t, o, h, l, c) # + heikin_ashi, bollinger, drawdown…
pv.regression(x, y, band=2) # OLS + confidence band (or method="loess")
pv.corr_matrix([a, b, c], names=["a", "b", "c"]) # diverging, locked to ±1
pv.psd(signal, sampleRate=1000) # Welch spectrum
pv.confusion_matrix(y_true, y_pred) # + roc_curve, pr_curve, calibration, embedding…
pv.surface(z, cols, rows) # 3D — orbit with the mouse
pv.polar_line(theta, r)
Plot, Plot3D and Polar are the full objects; the module-level names are
one-line shortcuts. Pass plot={...} to a shortcut to configure the plot itself:
pv.scatter(x, y, size=4, plot={"theme": "dark", "pick": "xy", "colorbar": False})
Model architecture
Hand a PyTorch, Keras, scikit-learn or ONNX model straight to
model_graph — the export happens in Python, the layout in the browser.
import torch, torchvision, photonviz as pv
model = torchvision.models.resnet18()
# 2D — a Netron-style DAG, with residual connections routed around the trunk.
pv.model_graph(model, example_input=torch.randn(1, 3, 224, 224), direction="horizontal")
# 3D — one cuboid per layer, sized from its output tensor: feature maps shrink
# while channel depth grows.
pv.model_graph_3d(
model,
example_input=torch.randn(1, 3, 224, 224),
labels="full",
plot={"aspectMode": "data", "projection": "orthographic", "showAxes": False},
)
| Framework | How it is read | Notes |
|---|---|---|
| PyTorch | torch.fx symbolic trace |
Branches and skip connections survive. Pass example_input= to record shapes. Untraceable models fall back to a flat chain of leaf modules. |
| Keras / TF | model.to_json() + per-layer shapes |
Sequential and functional, Keras 2 and 3. |
| scikit-learn | Pipeline / ColumnTransformer / FeatureUnion walk |
Parallel branches fan out and back in. An MLPClassifier expands into its real dense stack. |
| ONNX | MessageToDict + shape inference |
The framework-neutral path. |
Each cuboid is one layer: the visible face is its feature map, the thickness its channel count. Drag to orbit.
The exporters are usable on their own — pv.from_torch(model), pv.from_keras,
pv.from_sklearn, pv.from_onnx — and a hand-written
{"nodes": [...], "edges": [...]} graph works too.
Example notebooks
Runnable, in the repo — examples/notebooks/:
| Notebook | What it covers |
|---|---|
quickstart.ipynb |
The five-minute tour: a 200k-point line, a bubble chart with an OLS fit, a confusion matrix, a 3D model graph, a 3D surface. |
gallery.ipynb |
The full spread — distributions, fields, custom colours, finance, signal processing, ML metrics, model architecture, and 3D. |
How it works
photonviz is an anywidget, which is why the same
object renders in Jupyter Notebook 7, JupyterLab 4, VS Code and Colab with no
per-frontend code.
Chart calls build a plain dict. On sync, every array-like is swapped for a
{"$buffer": i} marker and its raw bytes are appended to a buffer list;
ipywidgets ships those as binary. The browser rebuilds typed-array views over
them and hands them to @photonviz/core, which uploads straight to GPU buffers.
Colours, names, extents and other structural values stay JSON.
All plots on a page share one WebGL2 context, so a notebook with dozens of charts will not exhaust the browser's context limit.
Development
From a checkout of the monorepo:
pnpm install
pnpm build:python # bundles the widget into src/photonviz/static/widget.js
cd python
pip install -e ".[dev]"
pytest
License
MIT
Metadata
Release files for photonviz 0.7.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| photonviz-0.7.2.tar.gz | 114.6 kB | Without provenance | Details for photonviz-0.7.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| photonviz-0.7.2-py3-none-any.whl | Python 3 | none | any | Details for photonviz-0.7.2-py3-none-any.whl |
Total release size: 232.6 kB
Release files / photonviz-0.7.2.tar.gz
| Download URL | photonviz-0.7.2.tar.gz |
|---|---|
| Size | 114.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ceb8f0b9a142dead2372f675958262b283cf871905c056c86d60fc56d947391c
|
|
BLAKE2b-256 checksum How to use checksums |
9ff4c45a8b283427015299d5a4dddebe1e496dbcadc6b3f9d22de34c06add6ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / photonviz-0.7.2-py3-none-any.whl
| Download URL | photonviz-0.7.2-py3-none-any.whl |
|---|---|
| Size | 118.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a47d8f67ff76e87a4207db3507f370f86fecb445b95fa8aa73b16eb067e8312
|
|
BLAKE2b-256 checksum How to use checksums |
fd95fc2e1d93f31633cf73b49dfa773ffce0e4baf73060361f47074983368d06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Security for photonviz 0.7.2
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.