Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 011a3f7

Browse files
Merge pull request matplotlib#24408 from PiotrStrzelczykX/pstrzelcz-fix-make_axes-parameters
Fix: restore make_axes to accept a tuple of axes
2 parents a1da538 + a928cec commit 011a3f7

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

‎lib/matplotlib/colorbar.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
End-users most likely won't need to directly use this module's API.
1212
"""
1313

14+
import collections.abc as collections_abc
1415
import logging
1516

1617
import numpy as np
@@ -1394,7 +1395,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
13941395
13951396
Parameters
13961397
----------
1397-
parents : `~.axes.Axes` or list or `numpy.ndarray` of `~.axes.Axes`
1398+
parents : `~.axes.Axes` or sequence or `numpy.ndarray` of `~.axes.Axes`
13981399
The Axes to use as parents for placing the colorbar.
13991400
%(_make_axes_kw_doc)s
14001401
@@ -1420,7 +1421,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
14201421
# reuse them, leading to a memory leak
14211422
if isinstance(parents, np.ndarray):
14221423
parents = list(parents.flat)
1423-
elif not isinstance(parents, list):
1424+
elif not isinstance(parents, collections_abc.Sequence):
14241425
parents = [parents]
14251426
fig = parents[0].get_figure()
14261427

‎lib/matplotlib/figure.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ def colorbar(
11951195
cax : `~matplotlib.axes.Axes`, optional
11961196
Axes into which the colorbar will be drawn.
11971197
1198-
ax : `~.axes.Axes` or list or `numpy.ndarray` of Axes, optional
1198+
ax : `~.axes.Axes` or sequence or `numpy.ndarray` of Axes, optional
11991199
One or more parent axes from which space for a new colorbar axes
12001200
will be stolen, if *cax* is None. This has no effect if *cax* is
12011201
set.

‎lib/matplotlib/tests/test_colorbar.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,3 +1199,14 @@ def test_colorbar_errors(kwargs, error, message):
11991199
kwargs['cax'] = ax.inset_axes([0, 1.05, 1, 0.05])
12001200
with pytest.raises(error, match=message):
12011201
fig.colorbar(im, **kwargs)
1202+
1203+
1204+
def test_colorbar_axes_parmeters():
1205+
fig, ax = plt.subplots(2)
1206+
im = ax[0].imshow([[0, 1], [2, 3]])
1207+
# colorbar should accept any form of axes sequence:
1208+
fig.colorbar(im, ax=ax)
1209+
fig.colorbar(im, ax=ax[0])
1210+
fig.colorbar(im, ax=[_ax for _ax in ax])
1211+
fig.colorbar(im, ax=(ax[0], ax[1]))
1212+
fig.draw_without_rendering()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /