> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.conductorquantum.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.conductorquantum.com/_mcp/server.

# 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](/_fern-files/conductor-quantum.docs.buildwithfern.com/669e092b2a53dc01451190056a1fefe30483050747106cc1f6d9b009ae8df72a/assets/stanza_live_plotting.gif)

## Quick Start with CLI

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

```bash
# Plots in browser (default) - opens at http://localhost:5006
stanza live-plot enable

# Plots in notebook cells (requires: pip install "cq-stanza[notebook]")
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:

```python
from stanza.plotter import enable_live_plotting

# Enable live plotting with browser backend
backend = enable_live_plotting(runner.context.resources.logger, backend="server", port=5006)

# Run your routine - plots update live at http://localhost:5006
result = 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\[notebook]"):

```python
from stanza.plotter import enable_live_plotting

# Enable inline plotting
backend = enable_live_plotting(runner.context.resources.logger, backend="inline")

# Run your routine - plots appear and update in the notebook cell
result = 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:

```bash
pip install "cq-stanza[notebook]"
```

## 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:

```python
from stanza.logger import DataLogger
from stanza.routines import RoutineRunner
from stanza.utils import load_device_config
from stanza.plotter import enable_live_plotting

# Load configuration
config = load_device_config("device.yaml")

# Create logger
logger = DataLogger(
    name="logger",
    routine_name="characterization",
    base_dir="./data",
    formats=["hdf5", "jsonl"]
)

# Create runner
runner = RoutineRunner(configs=[config], logger=logger)

# Enable live plotting (browser backend)
backend = enable_live_plotting(logger, backend="server", port=5006)

# Run routine - watch plots update at http://localhost:5006
result = runner.run("sweep_barrier", gate="G1", v_start=-2.0, v_stop=0.0, n_points=100)
```

## Disabling Live Plotting

To disable live plotting:

```bash
stanza live-plot disable
```

Or programmatically:

```python
from stanza.plotter import disable_live_plotting

disable_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:

```bash
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](/control/stanza/core-concepts/data-logging) - Learn how to configure the DataLogger that feeds live plotting
* [Routines](/control/stanza/core-concepts/routines/overview) - Write routines that automatically stream data to plots
* [Device Configuration](/control/stanza/core-concepts/device-configuration) - Set up your device for measurements