45
45
import matplotlib .cm as cm
46
46
import matplotlib .patches as mpatches
47
47
import matplotlib .path as mpath
48
+ import matplotlib .spines as mspines
48
49
import matplotlib .ticker as ticker
49
50
import matplotlib .transforms as mtransforms
50
51
import matplotlib ._layoutbox as layoutbox
@@ -321,6 +322,27 @@ def tick_values(self, vmin, vmax):
321
322
return ticks
322
323
323
324
325
+ class _ColorbarSpine (mspines .Spine ):
326
+ def __init__ (self , axes ):
327
+ super ().__init__ (axes , 'colorbar' ,
328
+ mpath .Path (np .empty ((0 , 2 )), closed = True ))
329
+
330
+ def get_window_extent (self , renderer = None ):
331
+ # This Spine has no Axis associated with it, and doesn't need to adjust
332
+ # its location, so we can directly get the window extent from the
333
+ # super-super-class.
334
+ return mpatches .Patch .get_window_extent (self , renderer = renderer )
335
+
336
+ def set_xy (self , xy ):
337
+ self ._path = mpath .Path (xy , closed = True )
338
+ self .stale = True
339
+
340
+ def draw (self , renderer ):
341
+ ret = mpatches .Patch .draw (self , renderer )
342
+ self .stale = False
343
+ return ret
344
+
345
+
324
346
class ColorbarBase :
325
347
r"""
326
348
Draw a colorbar in an existing axes.
@@ -427,7 +449,7 @@ def __init__(self, ax, cmap=None,
427
449
self .ax = ax
428
450
# Bind some methods to the axes to warn users against using them.
429
451
ax .set_xticks = ax .set_yticks = _set_ticks_on_axis_warn
430
- ax .set (frame_on = False , navigate = False )
452
+ ax .set (navigate = False )
431
453
432
454
if cmap is None :
433
455
cmap = cm .get_cmap ()
@@ -457,12 +479,9 @@ def __init__(self, ax, cmap=None,
457
479
self .solids = None
458
480
self .lines = []
459
481
460
- self .outline = mpatches .Polygon (
461
- np .empty ((0 , 2 )),
462
- edgecolor = mpl .rcParams ['axes.edgecolor' ], facecolor = 'none' ,
463
- linewidth = mpl .rcParams ['axes.linewidth' ], closed = True , zorder = 2 )
464
- ax .add_artist (self .outline )
465
- self .outline .set (clip_box = None , clip_path = None )
482
+ for spine in ax .spines .values ():
483
+ spine .set_visible (False )
484
+ self .outline = ax .spines ['outline' ] = _ColorbarSpine (ax )
466
485
467
486
self .patch = mpatches .Polygon (
468
487
np .empty ((0 , 2 )),
@@ -1304,12 +1323,9 @@ def update_bruteforce(self, mappable):
1304
1323
self .formatter = None
1305
1324
1306
1325
# clearing the axes will delete outline, patch, solids, and lines:
1307
- self .outline = mpatches .Polygon (
1308
- np .empty ((0 , 2 )),
1309
- edgecolor = mpl .rcParams ['axes.edgecolor' ], facecolor = 'none' ,
1310
- linewidth = mpl .rcParams ['axes.linewidth' ], closed = True , zorder = 2 )
1311
- self .ax .add_artist (self .outline )
1312
- self .outline .set (clip_box = None , clip_path = None )
1326
+ for spine in self .ax .spines .values ():
1327
+ spine .set_visible (False )
1328
+ self .outline = self .ax .spines ['outline' ] = _ColorbarSpine (self .ax )
1313
1329
self .patch = mpatches .Polygon (
1314
1330
np .empty ((0 , 2 )),
1315
1331
color = mpl .rcParams ['axes.facecolor' ], linewidth = 0.01 , zorder = - 1 )
0 commit comments