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

Skip to content

Commit a7cb796

Browse files
committed
Remove unnecessary gca management in Figure.colorbar.
colorbar() doesn't modify the current axes (anymore?).
1 parent f5ff5d7 commit a7cb796

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

lib/matplotlib/figure.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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)