Skip to content

Plotting

Basic radial scan plots. Nothing is interpolated, resampled, sorted or smoothed, and pyplot is never used. See Plotting.

plot_scans

plot_scans(
    experiment: AUCExperiment,
    *,
    ax: Axes | None = None,
    scan_ids: Sequence[str] | None = None,
    title: str | None = None,
    legend: bool = True,
    label_elapsed: bool = True,
    colormap: str = DEFAULT_COLORMAP,
    linewidth: float = 1.0,
    marker: str | None = None,
) -> Axes

Overlay the radial scans of experiment on one set of axes.

Each scan is drawn from its own stored (radius, signal) vectors, in stored order. Scans carrying no observations are skipped. Nothing is interpolated, resampled, sorted or smoothed.

Parameters:

Name Type Description Default
experiment AUCExperiment

The experiment to draw.

required
ax Axes | None

Axes to draw on. When omitted a new standalone figure is created (reachable as returned_axes.figure); pyplot is never used.

None
scan_ids Sequence[str] | None

Restrict to these scans, in the order given. Defaults to every scan, in stored order.

None
title str | None

Axes title. Defaults to the experiment identifier and name.

None
legend bool

Draw a legend when at least one scan was plotted.

True
label_elapsed bool

Append each scan's elapsed time to its legend entry when the value is present.

True
colormap str

Named matplotlib colormap used to colour scans by their order.

DEFAULT_COLORMAP
linewidth float

Line width for each scan.

1.0
marker str | None

Optional matplotlib marker for individual observations.

None

Returns:

Type Description
Axes

The axes drawn on.

Raises:

Type Description
PlottingError

if a requested scan identifier is absent, or if no selected scan carries any observation to draw.

Source code in src/openauc/plotting/scans.py
def plot_scans(
    experiment: AUCExperiment,
    *,
    ax: Axes | None = None,
    scan_ids: Sequence[str] | None = None,
    title: str | None = None,
    legend: bool = True,
    label_elapsed: bool = True,
    colormap: str = DEFAULT_COLORMAP,
    linewidth: float = 1.0,
    marker: str | None = None,
) -> Axes:
    """Overlay the radial scans of ``experiment`` on one set of axes.

    Each scan is drawn from its own stored ``(radius, signal)`` vectors, in
    stored order. Scans carrying no observations are skipped. Nothing is
    interpolated, resampled, sorted or smoothed.

    Args:
        experiment: The experiment to draw.
        ax: Axes to draw on. When omitted a new standalone figure is created
            (reachable as ``returned_axes.figure``); pyplot is never used.
        scan_ids: Restrict to these scans, in the order given. Defaults to every
            scan, in stored order.
        title: Axes title. Defaults to the experiment identifier and name.
        legend: Draw a legend when at least one scan was plotted.
        label_elapsed: Append each scan's elapsed time to its legend entry when
            the value is present.
        colormap: Named matplotlib colormap used to colour scans by their order.
        linewidth: Line width for each scan.
        marker: Optional matplotlib marker for individual observations.

    Returns:
        The axes drawn on.

    Raises:
        PlottingError: if a requested scan identifier is absent, or if no
            selected scan carries any observation to draw.
    """
    selected = _resolve_scan_ids(experiment, scan_ids)
    observations = experiment.observations
    by_id = _metadata_by_id(experiment)

    drawable: list[tuple[str, NDArray[np.float64], NDArray[np.float64]]] = []
    for scan_id in selected:
        radius, signal = observations.scan_vectors(scan_id)
        if radius.size:
            drawable.append((scan_id, radius, signal))

    if not drawable:
        raise PlottingError("no scan in the selection carries any observation to plot")

    axes = _new_axes() if ax is None else ax
    for colour, (scan_id, radius, signal) in zip(
        _colours(len(drawable), colormap), drawable, strict=True
    ):
        axes.plot(
            radius,
            signal,
            color=colour,
            linewidth=linewidth,
            marker=marker,
            label=_scan_label(scan_id, by_id.get(scan_id), show_elapsed=label_elapsed),
        )

    axes.set_xlabel(_axis_label("radius", observations.radius_unit))
    axes.set_ylabel(_axis_label("signal", observations.signal_unit))
    axes.set_title(title if title is not None else _default_title(experiment))
    if legend:
        axes.legend(loc="best", fontsize="small")
    return axes

plot_scan

plot_scan(
    experiment: AUCExperiment,
    scan_id: str,
    *,
    ax: Axes | None = None,
    title: str | None = None,
    legend: bool = False,
    label_elapsed: bool = True,
    colormap: str = DEFAULT_COLORMAP,
    linewidth: float = 1.0,
    marker: str | None = None,
) -> Axes

Draw a single radial scan. See :func:plot_scans for the shared rules.

Source code in src/openauc/plotting/scans.py
def plot_scan(
    experiment: AUCExperiment,
    scan_id: str,
    *,
    ax: Axes | None = None,
    title: str | None = None,
    legend: bool = False,
    label_elapsed: bool = True,
    colormap: str = DEFAULT_COLORMAP,
    linewidth: float = 1.0,
    marker: str | None = None,
) -> Axes:
    """Draw a single radial scan. See :func:`plot_scans` for the shared rules."""
    return plot_scans(
        experiment,
        ax=ax,
        scan_ids=(scan_id,),
        title=title,
        legend=legend,
        label_elapsed=label_elapsed,
        colormap=colormap,
        linewidth=linewidth,
        marker=marker,
    )