@@ -228,7 +228,11 @@ def draw(self, renderer):
228
228
return ret
229
229
230
230
231
- class _ColorbarLocator :
231
+ class _ColorbarAxesLocator :
232
+ """
233
+ Wrap any locator on the axes, or its position, to shrink the
234
+ inner axes if there are extend triangles at either min or max.
235
+ """
232
236
def __init__ (self , cbar ):
233
237
"""
234
238
*bounds* (a ``[l, b, w, h]`` rectangle) and *transform* together
@@ -248,36 +252,39 @@ def __call__(self, ax, renderer):
248
252
lim = self ._cbar ._long_axis ().get_view_interval ()
249
253
self ._cbar ._short_axis ().set_view_interval (* lim )
250
254
251
- pos = ax .get_position (original = True )
252
255
if self ._orig_locator is not None :
253
256
pos = self ._orig_locator (ax , renderer )
257
+ else :
258
+ pos = ax .get_position (original = True )
254
259
if self ._cbar .extend == 'neither' :
255
260
return pos
261
+
262
+ y , extendlen = self ._cbar ._proportional_y ()
263
+ if not self ._cbar ._extend_lower ():
264
+ extendlen [0 ] = 0
265
+ if not self ._cbar ._extend_upper ():
266
+ extendlen [1 ] = 0
267
+ len = sum (extendlen ) + 1
268
+ shrink = 1 / len
269
+ offset = extendlen [0 ] / len
270
+ # we need to reset the aspect ratio of the axes to account
271
+ # of the extends...
272
+ if not self ._cbar ._userax :
273
+ aspect = ax ._colorbar_info ['aspect' ]
256
274
else :
257
- y , extendlen = self ._cbar ._proportional_y ()
258
- if not self ._cbar ._extend_lower ():
259
- extendlen [0 ] = 0
260
- if not self ._cbar ._extend_upper ():
261
- extendlen [1 ] = 0
262
- len = sum (extendlen ) + 1
263
- shrink = 1 / len
264
- offset = extendlen [0 ] / len
265
- # we need to reset the aspect ratio of the axes to account
266
- # of the extends...
267
- if not self ._cbar ._userax :
268
- aspect = ax ._colorbar_info ['aspect' ]
269
- else :
270
- aspect = False
271
- if self ._cbar .orientation == 'vertical' :
272
- if aspect :
273
- ax .set_aspect (aspect * shrink )
274
- offset = offset * pos .height
275
- pos = pos .shrunk (1 , shrink ).translated (0 , offset )
276
- else :
277
- if aspect :
278
- ax .set_aspect (aspect / shrink )
279
- offset = offset * pos .width
280
- pos = pos .shrunk (shrink , 1 ).translated (offset , 0 )
275
+ aspect = False
276
+ # now shrink and/or offset to take into account the
277
+ # extend tri/rectangles.
278
+ if self ._cbar .orientation == 'vertical' :
279
+ if aspect :
280
+ ax .set_aspect (aspect * shrink )
281
+ offset = offset * pos .height
282
+ pos = pos .shrunk (1 , shrink ).translated (0 , offset )
283
+ else :
284
+ if aspect :
285
+ ax .set_aspect (aspect / shrink )
286
+ offset = offset * pos .width
287
+ pos = pos .shrunk (shrink , 1 ).translated (offset , 0 )
281
288
return pos
282
289
283
290
@@ -421,7 +428,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
421
428
422
429
self .ax = ax
423
430
self ._userax = userax
424
- self .ax ._axes_locator = _ColorbarLocator (self )
431
+ self .ax ._axes_locator = _ColorbarAxesLocator (self )
425
432
ax .set (navigate = False )
426
433
427
434
if extend is None :
@@ -606,8 +613,7 @@ def _add_solids_patches(self, X, Y, C, mappable):
606
613
607
614
def _do_extends (self , extendlen ):
608
615
"""
609
- Make adjustments of the inner axes for the extend triangles (or
610
- rectanges) and add them as patches.
616
+ Add the extend tri/rectangles on the outside of the axes.
611
617
"""
612
618
# extend lengths are fraction of the *inner* part of colorbar,
613
619
# not the total colorbar:
@@ -767,10 +773,6 @@ def add_lines(self, *args, **kwargs):
767
773
self .ax .add_collection (col )
768
774
self .stale = True
769
775
770
- def set_scale (self , scale ):
771
- self .ax .set_xscale (scale )
772
- self .ax .set_yscale (scale )
773
-
774
776
def update_ticks (self ):
775
777
"""
776
778
Setup the ticks and ticklabels. This should not be needed by users.
0 commit comments