Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5cb9719

Browse files
committed
Remove unnecessary gca management in Figure.colorbar.
colorbar() doesn't modify the current axes (anymore?). Also slightly tweak the docstring.
1 parent f5ff5d7 commit 5cb9719

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

lib/matplotlib/figure.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,13 +1221,13 @@ def colorbar(
12211221
12221222
The *shrink* kwarg provides a simple way to scale the colorbar with
12231223
respect to the axes. Note that if *cax* is specified, it determines the
1224-
size of the colorbar and *shrink* and *aspect* kwargs are ignored.
1224+
size of the colorbar, and *shrink* and *aspect* are ignored.
12251225
12261226
For more precise control, you can manually specify the positions of the
12271227
axes objects in which the mappable and the colorbar are drawn. In this
12281228
case, do not use any of the axes properties kwargs.
12291229
1230-
It is known that some vector graphics viewers (svg and pdf) renders
1230+
It is known that some vector graphics viewers (svg and pdf) render
12311231
white gaps between segments of the colorbar. This is due to bugs in
12321232
the viewers, not Matplotlib. As a workaround, the colorbar can be
12331233
rendered with overlapping segments::
@@ -1257,27 +1257,18 @@ def colorbar(
12571257
'the Colorbar, provide the *ax* argument to steal space '
12581258
'from it, or add *mappable* to an Axes.'))
12591259
ax = self.gca()
1260-
current_ax = self.gca()
1261-
userax = False
12621260
if (use_gridspec
12631261
and isinstance(ax, mpl.axes._base._AxesBase)
12641262
and ax.get_subplotspec()):
12651263
cax, kwargs = cbar.make_axes_gridspec(ax, **kwargs)
12661264
else:
12671265
cax, kwargs = cbar.make_axes(ax, **kwargs)
12681266
cax.grid(visible=False, which='both', axis='both')
1269-
else:
1270-
userax = True
1271-
1272-
# need to remove kws that cannot be passed to Colorbar
1273-
NON_COLORBAR_KEYS = ['fraction', 'pad', 'shrink', 'aspect', 'anchor',
1274-
'panchor']
1275-
cb_kw = {k: v for k, v in kwargs.items() if k not in NON_COLORBAR_KEYS}
1276-
1277-
cb = cbar.Colorbar(cax, mappable, **cb_kw)
12781267

1279-
if not userax:
1280-
self.sca(current_ax)
1268+
NON_COLORBAR_KEYS = [ # remove kws that cannot be passed to Colorbar
1269+
'fraction', 'pad', 'shrink', 'aspect', 'anchor', 'panchor']
1270+
cb = cbar.Colorbar(cax, mappable, **{
1271+
k: v for k, v in kwargs.items() if k not in NON_COLORBAR_KEYS})
12811272
self.stale = True
12821273
return cb
12831274

0 commit comments

Comments
 (0)