snnlab
API referencesnnlab.viz

snnlab.viz.scene

Complete declared API of the scene module, with signatures, data fields, validation and source.

Back to viz reference

An intentionally thin composition layer over Matplotlib.

The signatures, defaults, fields, docstrings and implementation excerpts below are generated from the Python source. Annotations are shown as declared; unannotated means the source supplies no type annotation. These pages document callable surfaces, including legacy support utilities, without promising backend support for every declaration.

SymbolKind
Panelclass
Sceneclass

Panel

View source

Structural protocol for a reusable panel: draw(ax, recording) renders initial state and update(frame) supplies its animation update. The protocol does not prescribe panel-specific scientific meaning.

Bases: Protocol. Inherited third-party framework APIs follow their owning library.

Panel.draw

View source

def Panel.draw(self, ax: Any, recording: Recording) -> Any
ParameterAnnotationDefaultMeaning
axAnyrequiredDefined by the source contract and implementation below.
recordingRecordingrequiredRetained Recording or recording selection, as annotated.

Return annotation: Any.

Implementation
def draw(self, ax: Any, recording: Recording) -> Any: ...

Panel.update

View source

def Panel.update(self, frame: int) -> object
ParameterAnnotationDefaultMeaning
frameintrequiredDefined by the source contract and implementation below.

Return annotation: object.

Implementation
def update(self, frame: int) -> object: ...
Complete class implementation
class Panel(Protocol):
    def draw(self, ax: Any, recording: Recording) -> Any: ...

    def update(self, frame: int) -> object: ...

Scene

View source

Thin Matplotlib composition over a validated Recording. add() accepts an explicit axis or a named FigureGrid region; on_frame() registers scene callbacks; update() collects panel and callback update results. The scene does not fabricate missing signals.

Source docstring:

Compose reusable and bespoke panels without hiding Matplotlib.

Class decorators: dataclass.

Dataclass constructor parameters. Factory defaults are shown as field declarations; omit these arguments to create fresh values per instance:

Scene(recording: Recording, figure: Any = None, layout: FigureGrid | None = None, panels: list[Panel] = field(default_factory=list), callbacks: list[Callable[[int, 'Scene'], object]] = field(default_factory=list))

Declared fields, including fields inherited from local data classes:

FieldAnnotationDefaultMeaning
recordingRecordingrequiredRetained Recording or recording selection, as annotated.
figureAnyNoneStored member of this data contract; see the class docstring and serialization methods.
layoutFigureGrid | NoneNoneStored member of this data contract; see the class docstring and serialization methods.
panelslist[Panel]field(default_factory=list)Stored member of this data contract; see the class docstring and serialization methods.
callbackslist[Callable[[int, 'Scene'], object]]field(default_factory=list)Stored member of this data contract; see the class docstring and serialization methods.

Scene.add

View source

def Scene.add(self, panel: Panel, *, axis: Any=None, region: str | None=None) -> Any

Source docstring:

Draw a panel on an axis, a named region, or a default axis.
ParameterAnnotationDefaultMeaning
panelPanelrequiredDefined by the source contract and implementation below.
axisAnyNoneDefined by the source contract and implementation below.
regionstr | NoneNoneDefined by the source contract and implementation below.

Return annotation: Any.

Return expressions (branch-dependent; names refer to the linked implementation):

ax

Explicit exceptions in this implementation; called helpers may raise additional errors:

Explicit exception expression
ValueError('provide either an axis or a figure-grid region')
ValueError('a figure-grid region requires a Scene layout')
Implementation
def add(
        self,
        panel: Panel,
        *,
        axis: Any = None,
        region: str | None = None,
    ) -> Any:
        """Draw a panel on an axis, a named region, or a default axis."""

        if axis is not None and region is not None:
            raise ValueError("provide either an axis or a figure-grid region")
        if region is not None:
            if self.layout is None:
                raise ValueError("a figure-grid region requires a Scene layout")
            ax = self.layout.add_axes(self.figure, region)
        else:
            ax = axis if axis is not None else self.figure.add_subplot(1, 1, 1)
        panel.draw(ax, self.recording)
        self.panels.append(panel)
        return ax

Scene.on_frame

View source

def Scene.on_frame(self, callback: Callable[[int, 'Scene'], object]) -> None
ParameterAnnotationDefaultMeaning
callbackCallable[[int, 'Scene'], object]requiredDefined by the source contract and implementation below.

Return annotation: None.

Implementation
def on_frame(self, callback: Callable[[int, "Scene"], object]) -> None:
        self.callbacks.append(callback)

Scene.update

View source

def Scene.update(self, frame: int) -> tuple[object, ...]
ParameterAnnotationDefaultMeaning
frameintrequiredDefined by the source contract and implementation below.

Return annotation: tuple[object, ...].

Return expressions (branch-dependent; names refer to the linked implementation):

tuple(artists)
Implementation
def update(self, frame: int) -> tuple[object, ...]:
        artists = [panel.update(frame) for panel in self.panels]
        artists.extend(
            callback(frame, self) for callback in self.callbacks
        )
        return tuple(artists)
Complete class implementation
class Scene:
    """Compose reusable and bespoke panels without hiding Matplotlib."""

    recording: Recording
    figure: Any = None
    layout: FigureGrid | None = None
    panels: list[Panel] = field(default_factory=list)
    callbacks: list[Callable[[int, "Scene"], object]] = field(
        default_factory=list
    )

    def __post_init__(self) -> None:
        if self.figure is None:
            self.figure = plt.figure()

    def add(
        self,
        panel: Panel,
        *,
        axis: Any = None,
        region: str | None = None,
    ) -> Any:
        """Draw a panel on an axis, a named region, or a default axis."""

        if axis is not None and region is not None:
            raise ValueError("provide either an axis or a figure-grid region")
        if region is not None:
            if self.layout is None:
                raise ValueError("a figure-grid region requires a Scene layout")
            ax = self.layout.add_axes(self.figure, region)
        else:
            ax = axis if axis is not None else self.figure.add_subplot(1, 1, 1)
        panel.draw(ax, self.recording)
        self.panels.append(panel)
        return ax

    def on_frame(self, callback: Callable[[int, "Scene"], object]) -> None:
        self.callbacks.append(callback)

    def update(self, frame: int) -> tuple[object, ...]:
        artists = [panel.update(frame) for panel in self.panels]
        artists.extend(
            callback(frame, self) for callback in self.callbacks
        )
        return tuple(artists)

On this page