From a928cec0172f4c6883ddb53a1d41c0344e60657e Mon Sep 17 00:00:00 2001 From: PIotr Strzelczyk Date: Wed, 9 Nov 2022 13:45:25 +0100 Subject: [PATCH] Fix: restore make_axes to accept a tuple of axes Allow to pass a tuple of axes as "ax" parameter of make_axes function Signed-off-by: Strzelczyk, Piotr --- lib/matplotlib/colorbar.py | 5 +++-- lib/matplotlib/figure.py | 2 +- lib/matplotlib/tests/test_colorbar.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 402ba4085e50..5a7fdf39931a 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -11,6 +11,7 @@ End-users most likely won't need to directly use this module's API. """ +import collections.abc as collections_abc import logging import numpy as np @@ -1403,7 +1404,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15, Parameters ---------- - parents : `~.axes.Axes` or list or `numpy.ndarray` of `~.axes.Axes` + parents : `~.axes.Axes` or sequence or `numpy.ndarray` of `~.axes.Axes` The Axes to use as parents for placing the colorbar. %(_make_axes_kw_doc)s @@ -1429,7 +1430,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15, # reuse them, leading to a memory leak if isinstance(parents, np.ndarray): parents = list(parents.flat) - elif not isinstance(parents, list): + elif not isinstance(parents, collections_abc.Sequence): parents = [parents] fig = parents[0].get_figure() diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 147500dd5451..a7272f2851d7 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -1191,7 +1191,7 @@ def colorbar( cax : `~matplotlib.axes.Axes`, optional Axes into which the colorbar will be drawn. - ax : `~.axes.Axes` or list or `numpy.ndarray` of Axes, optional + ax : `~.axes.Axes` or sequence or `numpy.ndarray` of Axes, optional One or more parent axes from which space for a new colorbar axes will be stolen, if *cax* is None. This has no effect if *cax* is set. diff --git a/lib/matplotlib/tests/test_colorbar.py b/lib/matplotlib/tests/test_colorbar.py index f23541c9df2f..38f4f27bc81a 100644 --- a/lib/matplotlib/tests/test_colorbar.py +++ b/lib/matplotlib/tests/test_colorbar.py @@ -1188,3 +1188,14 @@ def test_colorbar_errors(kwargs, error, message): kwargs['cax'] = ax.inset_axes([0, 1.05, 1, 0.05]) with pytest.raises(error, match=message): fig.colorbar(im, **kwargs) + + +def test_colorbar_axes_parmeters(): + fig, ax = plt.subplots(2) + im = ax[0].imshow([[0, 1], [2, 3]]) + # colorbar should accept any form of axes sequence: + fig.colorbar(im, ax=ax) + fig.colorbar(im, ax=ax[0]) + fig.colorbar(im, ax=[_ax for _ax in ax]) + fig.colorbar(im, ax=(ax[0], ax[1])) + fig.draw_without_rendering()