From a4d158ad506a308e49dfff8b6e96c7a8ce5d6e63 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Tue, 25 Aug 2026 08:02:12 +0200 Subject: [PATCH] Let plot_dataset take back the colorbars it returns plot_dataset returns a list of colorbars whose entries are None for the 1D plots, but its colorbars argument only accepted a sequence that was either all colorbars or all None. Passing the result back in, which is how the offline plotting tutorial plots into the same axes again, was therefore a type error. Take a Sequence[Colorbar | None]. A Sequence[Colorbar] is still one of those, so nothing that worked before stops working, and the body already built and handled lists containing None. plot_by_id forwards to plot_dataset and returns the same type, so it is widened with it. --- docs/changes/newsfragments/8388.improved | 5 +++++ src/qcodes/dataset/plotting.py | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 docs/changes/newsfragments/8388.improved diff --git a/docs/changes/newsfragments/8388.improved b/docs/changes/newsfragments/8388.improved new file mode 100644 index 00000000000..83aa40c75dd --- /dev/null +++ b/docs/changes/newsfragments/8388.improved @@ -0,0 +1,5 @@ +The ``colorbars`` argument of :func:`.plot_dataset` and :func:`.plot_by_id` now +accepts a sequence that may contain ``None``. Both functions return a list of +colorbars in which the entries for 1D plots are ``None``, so passing the result +back in, which is how you plot into the same axes again, did not match the +declared argument type. A sequence of colorbars is still accepted. diff --git a/src/qcodes/dataset/plotting.py b/src/qcodes/dataset/plotting.py index 6145968e782..11c5ee79c35 100644 --- a/src/qcodes/dataset/plotting.py +++ b/src/qcodes/dataset/plotting.py @@ -95,7 +95,10 @@ def heatmaphandler(**kwargs: Any) -> Any: def plot_dataset( dataset: DataSetProtocol, axes: Axes | Sequence[Axes] | None = None, - colorbars: Colorbar | Sequence[Colorbar] | Sequence[None] | None = None, + # ``Sequence[Colorbar | None]`` so that the list of colorbars returned by + # this function can be passed straight back in, which is how you plot into + # the same axes again. A ``Sequence[Colorbar]`` is also one of these. + colorbars: Colorbar | Sequence[Colorbar | None] | None = None, rescale_axes: bool = True, auto_color_scale: bool | None = None, cutoff_percentile: tuple[float, float] | float | None = None, @@ -417,7 +420,7 @@ def plot_and_save_image( def plot_by_id( run_id: int, axes: Axes | Sequence[Axes] | None = None, - colorbars: Colorbar | Sequence[Colorbar] | None = None, + colorbars: Colorbar | Sequence[Colorbar | None] | None = None, rescale_axes: bool = True, auto_color_scale: bool | None = None, cutoff_percentile: tuple[float, float] | float | None = None,