Plotly Utils
Stateless Plotly visualization utilities.
Replaces the legacy BaseVisualizationLens classes with pure functions
that map data to plotly.graph_objects.Figure instances.
These functions do not accept Results objects; they operate on raw
Python data or tensors so they can be used independently of the pipeline.
Requires the plot extra (install with pip install murano-interp[plot]).
plot_heatmap
Section titled “plot_heatmap”def plot_heatmap(z_data: list[list[float]] | list[list[int]], x_labels: list[str] | None = None, y_labels: list[str] | None = None, title: str = '', color_scale: str = 'Viridis', hover_data: list[list[str]] | None = None, colorbar_title: str = '', square: bool = False, zmid: float | None = None) -> go.Figure:Create a heatmap figure.
Args:
z_data: 2-D matrix of values (rows × columns).x_labels: Labels for the x-axis (columns).y_labels: Labels for the y-axis (rows). Defaults to["Layer 0", "Layer 1", …]whenNone.title: Plot title.color_scale: Plotly colorscale name (e.g."Viridis","RdBu_r").hover_data: Optional 2-D list of custom hover text, same shape asz_data.colorbar_title: Label for the colorbar (the value legend); blank hides it.square: If True, force square cells (equal x and y scale), for a matrix- whose axes share a unit such as an attention pattern.
zmid: Value anchored to the middle of the colorscale. Pass0with a- diverging scale so that the neutral color means zero; otherwise an
- asymmetric range silently shifts the midpoint and shades zero as if
- it had a sign.
Returns:
- A
plotly.graph_objects.Figurewith a single heatmap trace.
plot_line_chart
Section titled “plot_line_chart”def plot_line_chart(x_data: list[float] | list[int], y_series: dict[str, list[float] | list[int]], title: str = '', x_label: str = '', y_label: str = '') -> go.Figure:Create a multi-line line chart figure.
Args:
x_data: Values for the x-axis.y_series: Mapping from trace name to y-values. Each entry produces- one scatter trace.
title: Plot title.x_label: Label for the x-axis.y_label: Label for the y-axis.
Returns:
- A
plotly.graph_objects.Figurewith one scatter trace per entry - in
y_series.
save_figure
Section titled “save_figure”def save_figure(fig: go.Figure, path: str | Path, width: int | None = None, height: int | None = None, scale: float = 2) -> Path:Save a Plotly figure to disk, preferring a static image with an HTML fallback.
fig.write_image needs a Chrome/kaleido backend that is not always present
(headless GPU compute nodes are a common case); when it is unavailable the
figure is instead written as a self-contained HTML file (.html next to the
requested path) so it is never lost.
Args:
fig: The figure to save.path: Destination path. A static-image suffix (.png,.svg, …) is- honored when image export works; otherwise
.htmlis used. width: Image width in pixels (image export only).height: Image height in pixels (image export only).scale: Image resolution multiplier (image export only).
Returns:
- The path actually written (the requested image path, or the
.html - fallback).