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 a928cec

Browse files
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 <piotr.strzelczyk@intel.com>
1 parent 8d8ae7f commit a928cec

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
@@ -1403,7 +1404,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
14031404
14041405
Parameters
14051406
----------
1406-
parents : `~.axes.Axes` or list or `numpy.ndarray` of `~.axes.Axes`
1407+
parents : `~.axes.Axes` or sequence or `numpy.ndarray` of `~.axes.Axes`
14071408
The Axes to use as parents for placing the colorbar.
14081409
%(_make_axes_kw_doc)s
14091410
@@ -1429,7 +1430,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
14291430
# reuse them, leading to a memory leak
14301431
if isinstance(parents, np.ndarray):
14311432
parents = list(parents.flat)
1432-
elif not isinstance(parents, list):
1433+
elif not isinstance(parents, collections_abc.Sequence):
14331434
parents = [parents]
14341435
fig = parents[0].get_figure()
14351436

‎lib/matplotlib/figure.py‎

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

‎lib/matplotlib/tests/test_colorbar.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,3 +1188,14 @@ def test_colorbar_errors(kwargs, error, message):
11881188
kwargs['cax'] = ax.inset_axes([0, 1.05, 1, 0.05])
11891189
with pytest.raises(error, match=message):
11901190
fig.colorbar(im, **kwargs)
1191+
1192+
1193+
def test_colorbar_axes_parmeters():
1194+
fig, ax = plt.subplots(2)
1195+
im = ax[0].imshow([[0, 1], [2, 3]])
1196+
# colorbar should accept any form of axes sequence:
1197+
fig.colorbar(im, ax=ax)
1198+
fig.colorbar(im, ax=ax[0])
1199+
fig.colorbar(im, ax=[_ax for _ax in ax])
1200+
fig.colorbar(im, ax=(ax[0], ax[1]))
1201+
fig.draw_without_rendering()

0 commit comments

Comments
(0)

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