@@ -353,10 +353,9 @@ class ColorbarBase:
353353 ax : `~matplotlib.axes.Axes`
354354 The `~.axes.Axes` instance in which the colorbar is drawn.
355355 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).
358357 dividers : `.LineCollection`
359- A LineCollection if *drawedges* is ``True``, otherwise ``None`` .
358+ A LineCollection (empty if *drawedges* is ``False``) .
360359
361360 Parameters
362361 ----------
@@ -464,12 +463,18 @@ def __init__(self, ax, cmap=None,
464463 linewidth = mpl .rcParams ['axes.linewidth' ], closed = True , zorder = 2 )
465464 ax .add_artist (self .outline )
466465 self .outline .set (clip_box = None , clip_path = None )
466+
467467 self .patch = mpatches .Polygon (
468468 np .empty ((0 , 2 )),
469469 color = mpl .rcParams ['axes.facecolor' ], linewidth = 0.01 , zorder = - 1 )
470470 ax .add_artist (self .patch )
471471
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+
473478 self .locator = None
474479 self .formatter = None
475480 self ._manual_tick_data_values = None
@@ -819,18 +824,13 @@ def _add_solids(self, X, Y, C):
819824 if self .solids is not None :
820825 self .solids .remove ()
821826 self .solids = col
822- if self .dividers is not None :
823- self .dividers .remove ()
824- self .dividers = None
827+
825828 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 )
834834
835835 def add_lines (self , levels , colors , linewidths , erase = True ):
836836 """
@@ -1317,7 +1317,6 @@ def update_bruteforce(self, mappable):
13171317 self .ax .add_artist (self .patch )
13181318 self .solids = None
13191319 self .lines = []
1320- self .dividers = None
13211320 self .update_normal (mappable )
13221321 self .draw_all ()
13231322 if isinstance (self .mappable , contour .ContourSet ):
@@ -1646,16 +1645,7 @@ def _add_solids(self, X, Y, C):
16461645
16471646 self .solids_patches = patches
16481647
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 [])
16591649
16601650
16611651def colorbar_factory (cax , mappable , ** kwargs ):
0 commit comments