@@ -255,7 +255,7 @@ def __init__(self, ax, cmap=None,
255255 self .filled = filled
256256 self .extendfrac = extendfrac
257257 self .solids = None
258- self .lines = None
258+ self .lines = list ()
259259 self .outline = None
260260 self .patch = None
261261 self .dividers = None
@@ -467,14 +467,18 @@ def _add_solids(self, X, Y, C):
467467 )
468468 self .ax .add_collection (self .dividers )
469469
470- def add_lines (self , levels , colors , linewidths ):
470+ def add_lines (self , levels , colors , linewidths , erase = True ):
471471 '''
472472 Draw lines on the colorbar.
473473
474474 *colors* and *linewidths* must be scalars or
475475 sequences the same length as *levels*.
476+
477+ Set *erase* to False to add lines without first
478+ removing any previously added lines.
476479 '''
477480 y = self ._locate (levels )
481+ nlevs = len (levels )
478482 igood = (y < 1.001 ) & (y > - 0.001 )
479483 y = y [igood ]
480484 if cbook .iterable (colors ):
@@ -490,9 +494,10 @@ def add_lines(self, levels, colors, linewidths):
490494 xy = [zip (Y [i ], X [i ]) for i in xrange (N )]
491495 col = collections .LineCollection (xy , linewidths = linewidths )
492496
493- if self .lines :
494- self .lines .remove ()
495- self .lines = col
497+ if erase and self .lines :
498+ for lc in self .lines .pop ():
499+ lc .remove ()
500+ self .lines .append (col )
496501 col .set_color (colors )
497502 self .ax .add_collection (col )
498503
@@ -843,10 +848,13 @@ def on_mappable_changed(self, mappable):
843848 self .set_clim (mappable .get_clim ())
844849 self .update_normal (mappable )
845850
846- def add_lines (self , CS ):
851+ def add_lines (self , CS , erase = True ):
847852 '''
848853 Add the lines from a non-filled
849854 :class:`~matplotlib.contour.ContourSet` to the colorbar.
855+
856+ Set *erase* to False if these lines should be added to
857+ any pre-existing lines.
850858 '''
851859 if not isinstance (CS , contour .ContourSet ) or CS .filled :
852860 raise ValueError ('add_lines is only for a ContourSet of lines' )
@@ -860,7 +868,8 @@ def add_lines(self, CS):
860868 #tcolors = [col.get_colors()[0] for col in CS.collections]
861869 #tlinewidths = [col.get_linewidth()[0] for lw in CS.collections]
862870 #print 'tlinewidths:', tlinewidths
863- ColorbarBase .add_lines (self , CS .levels , tcolors , tlinewidths )
871+ ColorbarBase .add_lines (self , CS .levels , tcolors , tlinewidths ,
872+ erase = erase )
864873
865874 def update_normal (self , mappable ):
866875 '''
@@ -893,7 +902,7 @@ def update_bruteforce(self, mappable):
893902 self .outline = None
894903 self .patch = None
895904 self .solids = None
896- self .lines = None
905+ self .lines = list ()
897906 self .dividers = None
898907 self .set_alpha (mappable .get_alpha ())
899908 self .cmap = mappable .cmap
0 commit comments