Skip to content

scenex#

scenex is a library for describing and visualizing scenes, with minimal dependencies.

  • Declarative


    Scenes are created by pydantic models that say what to show instead of how to show it.

  • Evented


    Nodes can react to changes throughout the scene — update your data, and the scene updates with it.

  • Flexible


    Visualize with vispy or pygfx, rendered to widgets in qtpy, jupyter, or wx


In development

scenex is a work in progress. The public API may change between releases.

Installation#

Because scenex can run with different visualization and widget backends, it doesn't ship with any backends by default. You can install the backends you'll like to use with extras:

pip install "scenex[pygfx,pyqt6]"
pip install "scenex[pygfx,jupyter]"

See the install istructions for comprehensive installation instructions!

Usage#

import numpy as np
import scenex as snx

# A single node — show() wraps it in a Scene and View for you
data = np.random.rand(100, 100).astype(np.float32)
img  = snx.Image(data=data)

snx.show(img)
snx.run()            # enter the event loop (not needed in Jupyter)

Mutating the model after it is displayed updates the rendered scene immediately:

from cmap import Colormap

img.cmap   = Colormap("viridis")
img.clims  = (0.2, 0.8)
img.opacity = 0.7

Alternatives#

Like any tool, scenex is not a panacea. It aims to be flexible, describing scenes at a high level and abstracting away graphics primitives, animation loops, etc. If you need lower-level access, consider using pygfx, vispy, or datoviz directly.

The primary focus of scenex is rendering scenes. While you can render anything in a scene, you might get more convenience from alternative visualization tools:

I want to visualize... Consider
plots matplotlib, fastplotlib, Plotly, Bokeh, Vega-Altair
nD datasets napari
3D meshes / geometry PyVista, vedo