Skip to main content

Photon

photonviz

GPU-accelerated (WebGL2) charts for Jupyter, JupyterLab and Google Colab.

PyPI downloads Python versions WebGL2 Jupyter · Lab · Colab MIT · 📖 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.

A 200,000-point line chart rendered by photonviz in JupyterLab

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.

A CNN drawn as tensor-shaped 3D blocks inside a notebook

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.

Bubble chart with a least-squares fit and confidence band A lit 3D surface rendered in a notebook cell

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

photonviz-0.5.0.tar.gz (91.2 kB view details)

Uploaded Source

Built Distribution

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

photonviz-0.5.0-py3-none-any.whl (93.5 kB view details)

Uploaded Python 3

File details

Details for the file photonviz-0.5.0.tar.gz.

File metadata

  • Download URL: photonviz-0.5.0.tar.gz
  • Upload date:
  • Size: 91.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for photonviz-0.5.0.tar.gz
Algorithm Hash digest
SHA256 ba35044df7896f093e8548bdb1cbfdc93ee1fded61ad5a708867eb9a2123d802
MD5 65d79ea4aa1153db128b156a10d4534b
BLAKE2b-256 00960aec6edb81aebaad2c992f641bc468e0d99a469b854d0b4ea264221c2aab

See more details on using hashes here.

File details

Details for the file photonviz-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: photonviz-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 93.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for photonviz-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35acaa2caba59bf89405c621daab0a97a37a00f8aee8b5417864888c5d367540
MD5 4cad6d9d039361921266ff64a423104f
BLAKE2b-256 e3d9defb4cfa881fbaeec898a847cb53acdda0b95fb47d45e86915cd2c9a50d6

See more details on using hashes here.

Release history Release notifications | RSS feed

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.0

2 files

This release

0.5.0 This release

2 files

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