Skip to navigation

stanza.plotter.backends.utils

Shared utilities for plotting backends.

This module centralizes small, reusable helpers used by multiple plotting backends to keep implementations minimal and consistent.

Module Contents

Classes

NameDescription
PlotSpecPlot specification with type-safe fields.
PlotStateComplete plot state: source, figure, and spec in one place.

Functions

NameDescription
prepare_heatmap_dataCalculate rect sizes and update color range for heatmap data.
make_line_plotCreate a 1D line plot.
make_heatmap_plotCreate a 2D heatmap plot.

Data

LINE_PLOT_WIDTH LINE_PLOT_HEIGHT HEATMAP_WIDTH HEATMAP_HEIGHT

API

stanza.plotter.backends.utils.LINE_PLOT_WIDTH

Value: 800

stanza.plotter.backends.utils.LINE_PLOT_HEIGHT

Value: 400

stanza.plotter.backends.utils.HEATMAP_WIDTH

Value: 800

stanza.plotter.backends.utils.HEATMAP_HEIGHT

Value: 600

class stanza.plotter.backends.utils.PlotSpec

Plot specification with type-safe fields.

name: str

Value: None

plot_type: str

Value: None

x_label: str

Value: None

y_label: str

Value: None

z_label: str | None

Value: None

cell_size: tuple[float, float] | None

Value: None

mapper: bokeh.models.LinearColorMapper | None

Value: None

dx: float | None

Value: None

dy: float | None

Value: None

value_min: float

Value: float(...)

value_max: float

Value: float(...)

class stanza.plotter.backends.utils.PlotState

Complete plot state: source, figure, and spec in one place.

Single source of truth for a plot’s data, visualization, and configuration. Ownership is clear: whoever has the PlotState owns the entire plot.

source: bokeh.models.ColumnDataSource

Value: None

figure: typing.Any

Value: None

spec: stanza.plotter.backends.utils.PlotSpec

Value: None

stanza.plotter.backends.utils.prepare_heatmap_data(
data: dict[str, typing.Any],
existing_data: dict[str, typing.Any],
spec: stanza.plotter.backends.utils.PlotSpec
) -> dict[str, typing.Any]

Calculate rect sizes and update color range for heatmap data.

Parameters:

data
dict[str, typing.Any]

New data to add (x, y, value)

existing_data
dict[str, typing.Any]

Existing data in the data source

spec
stanza.plotter.backends.utils.PlotSpec

Plot specification with dx, dy, value_min, value_max

Returns:

Updated data with width and height fields added

stanza.plotter.backends.utils.make_line_plot(
name: str,
x_label: str,
y_label: str
) -> stanza.plotter.backends.utils.PlotState

Create a 1D line plot.

Returns complete PlotState with source, figure, and spec.

stanza.plotter.backends.utils.make_heatmap_plot(
name: str,
x_label: str,
y_label: str,
z_label: str | None,
cell_size: tuple[float, float] | None
) -> stanza.plotter.backends.utils.PlotState

Create a 2D heatmap plot.

Returns complete PlotState with source, figure, and spec.