@@ -353,10 +353,9 @@ class ColorbarBase:
353
353
ax : `~matplotlib.axes.Axes`
354
354
The `~.axes.Axes` instance in which the colorbar is drawn.
355
355
lines : list
356
- A list of `.LineCollection` if lines were drawn, otherwise
357
- an empty list.
356
+ A list of `.LineCollection` (empty if no lines were drawn).
358
357
dividers : `.LineCollection`
359
- A LineCollection if *drawedges* is ``True``, otherwise ``None`` .
358
+ A LineCollection (empty if *drawedges* is ``False``) .
360
359
361
360
Parameters
362
361
----------
@@ -464,12 +463,18 @@ def __init__(self, ax, cmap=None,
464
463
linewidth = mpl .rcParams ['axes.linewidth' ], closed = True , zorder = 2 )
465
464
ax .add_artist (self .outline )
466
465
self .outline .set (clip_box = None , clip_path = None )
466
+
467
467
self .patch = mpatches .Polygon (
468
468
np .empty ((0 , 2 )),
469
469
color = mpl .rcParams ['axes.facecolor' ], linewidth = 0.01 , zorder = - 1 )
470
470
ax .add_artist (self .patch )
471
471
472
- self .dividers = None
472
+ self .dividers = collections .LineCollection (
473
+ [],
474
+ colors = [mpl .rcParams ['axes.edgecolor' ]],
475
+ linewidths = [0.5 * mpl .rcParams ['axes.linewidth' ]])
476
+ self .ax .add_collection (self .dividers )
477
+
473
478
self .locator = None
474
479
self .formatter = None
475
480
self ._manual_tick_data_values = None
@@ -819,18 +824,13 @@ def _add_solids(self, X, Y, C):
819
824
if self .solids is not None :
820
825
self .solids .remove ()
821
826
self .solids = col
822
- if self .dividers is not None :
823
- self .dividers .remove ()
824
- self .dividers = None
827
+
825
828
if self .drawedges :
826
- linewidths = (0.5 * mpl .rcParams ['axes.linewidth' ],)
827
- self .dividers = collections .LineCollection (
828
- self ._edges (X , Y ),
829
- colors = (mpl .rcParams ['axes.edgecolor' ],),
830
- linewidths = linewidths )
831
- self .ax .add_collection (self .dividers )
832
- elif len (self ._y ) >= self .n_rasterize :
833
- self .solids .set_rasterized (True )
829
+ self .dividers .set_segments (self ._edges (X , Y ))
830
+ else :
831
+ self .dividers .set_segments ([])
832
+ if len (self ._y ) >= self .n_rasterize :
833
+ self .solids .set_rasterized (True )
834
834
835
835
def add_lines (self , levels , colors , linewidths , erase = True ):
836
836
"""
@@ -1317,7 +1317,6 @@ def update_bruteforce(self, mappable):
1317
1317
self .ax .add_artist (self .patch )
1318
1318
self .solids = None
1319
1319
self .lines = []
1320
- self .dividers = None
1321
1320
self .update_normal (mappable )
1322
1321
self .draw_all ()
1323
1322
if isinstance (self .mappable , contour .ContourSet ):
@@ -1646,16 +1645,7 @@ def _add_solids(self, X, Y, C):
1646
1645
1647
1646
self .solids_patches = patches
1648
1647
1649
- if self .dividers is not None :
1650
- self .dividers .remove ()
1651
- self .dividers = None
1652
-
1653
- if self .drawedges :
1654
- self .dividers = collections .LineCollection (
1655
- self ._edges (X , Y ),
1656
- colors = (mpl .rcParams ['axes.edgecolor' ],),
1657
- linewidths = (0.5 * mpl .rcParams ['axes.linewidth' ],))
1658
- self .ax .add_collection (self .dividers )
1648
+ self .dividers .set_segments (self ._edges (X , Y ) if self .drawedges else [])
1659
1649
1660
1650
1661
1651
def colorbar_factory (cax , mappable , ** kwargs ):
0 commit comments