Movatterモバイル変換


[0]ホーム

URL:


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

Commit7f5335a

Browse files
authored
Merge pull request#24737 from tacaswell/mnt/forgiving_colorbar_input
MNT: make fig.colorbar(..., ax=INPUT) even more forgiving
2 parents12402f4 +06396e2 commit7f5335a

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

‎lib/matplotlib/colorbar.py

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

14-
importcollections.abcascollections_abc
1514
importlogging
1615

1716
importnumpyasnp
@@ -1395,7 +1394,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
13951394
13961395
Parameters
13971396
----------
1398-
parents : `~.axes.Axes` orsequence or `numpy.ndarray` of `~.axes.Axes`
1397+
parents : `~.axes.Axes` oriterable or `numpy.ndarray` of `~.axes.Axes`
13991398
The Axes to use as parents for placing the colorbar.
14001399
%(_make_axes_kw_doc)s
14011400
@@ -1421,8 +1420,11 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
14211420
# reuse them, leading to a memory leak
14221421
ifisinstance(parents,np.ndarray):
14231422
parents=list(parents.flat)
1424-
elifnotisinstance(parents,collections_abc.Sequence):
1423+
elifnp.iterable(parents):
1424+
parents=list(parents)
1425+
else:
14251426
parents= [parents]
1427+
14261428
fig=parents[0].get_figure()
14271429

14281430
pad0=0.05iffig.get_constrained_layout()elseloc_settings['pad']

‎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` orsequence or `numpy.ndarray` of Axes, optional
1198+
ax : `~.axes.Axes` oriterable 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,4 +1209,5 @@ def test_colorbar_axes_parmeters():
12091209
fig.colorbar(im,ax=ax[0])
12101210
fig.colorbar(im,ax=[_axfor_axinax])
12111211
fig.colorbar(im,ax=(ax[0],ax[1]))
1212+
fig.colorbar(im,ax={i:_axfori,_axinenumerate(ax)}.values())
12121213
fig.draw_without_rendering()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp