Live Plotting

Visualize your data in real-time as routines execute. Stanza supports two plotting backends to fit different workflows - whether you’re working in a Jupyter notebook, running scripts from the command line, or running routines in your IDE.

Stanza Live Plotting Demo
Stanza inline live plotting in a jupyter notebook.

Quick Start with CLI

Enable live plotting in your notebook or script with a single command:

$# Plots in browser (default) - opens at http://localhost:5006
>stanza live-plot enable
>
># Plots in notebook cells (requires: pip install "cq-stanza[notebooks]")
>stanza live-plot enable --backend inline

Once enabled, the DataLogger automatically detects the configuration and streams data to plots as your routines run.

Python API

You can also enable live plotting programmatically for more control over the plotting backend and configuration.

Server Backend

Opens plots in a browser window - works in any environment including remote servers:

1from stanza.plotter import enable_live_plotting
2
3# Enable live plotting with browser backend
4backend = enable_live_plotting(runner.context.resources.logger, backend="server", port=5006)
5
6# Run your routine - plots update live at http://localhost:5006
7result = runner.run("sweep_barrier")

The server backend is ideal for:

  • Remote development environments
  • Long-running experiments you want to monitor from another machine
  • Situations where you want plots separate from your notebook

Inline Backend

Displays plots directly in notebook cells - requires jupyter_bokeh (pip install “cq-stanza[notebooks]”):

1from stanza.plotter import enable_live_plotting
2
3# Enable inline plotting
4backend = enable_live_plotting(runner.context.resources.logger, backend="inline")
5
6# Run your routine - plots appear and update in the notebook cell
7result = runner.run("sweep_barrier")

The inline backend is ideal for:

  • Interactive notebook workflows
  • Quick data exploration
  • When you want plots embedded alongside your code

Installation Requirements

The server backend works out of the box with Stanza. For inline plotting in Jupyter notebooks, install the additional dependency:

$pip install "cq-stanza[notebooks]"

Plot Types

Stanza automatically chooses the appropriate plot type based on your data:

1D Line Plots: Used for single-parameter sweeps like barrier gate pinchoffs or plunger gate sweeps. The x-axis shows the swept voltage, and the y-axis shows the measured signal (typically current).

2D Heatmaps: Used for two-parameter sweeps like charge stability diagrams. Both axes show swept voltages, and the color represents the measured signal intensity.

Plots update in real-time as data is logged, allowing you to monitor your measurements as they run and make decisions about whether to continue or adjust parameters.

Complete Example

Here’s a complete workflow using live plotting with a barrier sweep:

1from stanza.logger import DataLogger
2from stanza.routines import RoutineRunner
3from stanza.utils import load_device_config
4from stanza.plotter import enable_live_plotting
5
6# Load configuration
7config = load_device_config("device.yaml")
8
9# Create logger
10logger = DataLogger(
11 name="logger",
12 routine_name="characterization",
13 base_dir="./data",
14 formats=["hdf5", "jsonl"]
15)
16
17# Create runner
18runner = RoutineRunner(configs=[config], logger=logger)
19
20# Enable live plotting (browser backend)
21backend = enable_live_plotting(logger, backend="server", port=5006)
22
23# Run routine - watch plots update at http://localhost:5006
24result = runner.run("sweep_barrier", gate="G1", v_start=-2.0, v_stop=0.0, n_points=100)

Disabling Live Plotting

To disable live plotting:

$stanza live-plot disable

Or programmatically:

1from stanza.plotter import disable_live_plotting
2
3disable_live_plotting(runner.context.resources.logger)

Tips and Best Practices

Use server backend for remote work: If you’re SSH’d into a lab computer, the server backend lets you view plots in your local browser by port forwarding:

$ssh -L 5006:localhost:5006 user@lab-computer

Monitor long measurements: Live plotting is especially useful for long 2D sweeps where you want to see data quality before the entire measurement completes.

Adjust plot refresh rate: For very fast measurements, you may want to reduce plot update frequency to avoid performance overhead. This can be configured through the plotting backend initialization.

Check data quality early: Live plots let you catch issues like noise, drift, or saturation early in your measurement, saving time by allowing you to stop and adjust parameters if needed.

Next Steps

  • Data Logging - Learn how to configure the DataLogger that feeds live plotting
  • Routines - Write routines that automatically stream data to plots
  • Device Configuration - Set up your device for measurements