@@ -1257,27 +1257,18 @@ def colorbar(
1257
1257
'the Colorbar, provide the *ax* argument to steal space '
1258
1258
'from it, or add *mappable* to an Axes.' ))
1259
1259
ax = self .gca ()
1260
- current_ax = self .gca ()
1261
- userax = False
1262
1260
if (use_gridspec
1263
1261
and isinstance (ax , mpl .axes ._base ._AxesBase )
1264
1262
and ax .get_subplotspec ()):
1265
1263
cax , kwargs = cbar .make_axes_gridspec (ax , ** kwargs )
1266
1264
else :
1267
1265
cax , kwargs = cbar .make_axes (ax , ** kwargs )
1268
1266
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 )
1278
1267
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 })
1281
1272
self .stale = True
1282
1273
return cb
1283
1274
0 commit comments