Skip to content

Fix: restore make_axes to accept a tuple of axes #24408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()