@@ -255,7 +255,7 @@ def __init__(self, ax, cmap=None,
255
255
self .filled = filled
256
256
self .extendfrac = extendfrac
257
257
self .solids = None
258
- self .lines = None
258
+ self .lines = list ()
259
259
self .outline = None
260
260
self .patch = None
261
261
self .dividers = None
@@ -467,14 +467,18 @@ def _add_solids(self, X, Y, C):
467
467
)
468
468
self .ax .add_collection (self .dividers )
469
469
470
- def add_lines (self , levels , colors , linewidths ):
470
+ def add_lines (self , levels , colors , linewidths , erase = True ):
471
471
'''
472
472
Draw lines on the colorbar.
473
473
474
474
*colors* and *linewidths* must be scalars or
475
475
sequences the same length as *levels*.
476
+
477
+ Set *erase* to False to add lines without first
478
+ removing any previously added lines.
476
479
'''
477
480
y = self ._locate (levels )
481
+ nlevs = len (levels )
478
482
igood = (y < 1.001 ) & (y > - 0.001 )
479
483
y = y [igood ]
480
484
if cbook .iterable (colors ):
@@ -490,9 +494,10 @@ def add_lines(self, levels, colors, linewidths):
490
494
xy = [zip (Y [i ], X [i ]) for i in xrange (N )]
491
495
col = collections .LineCollection (xy , linewidths = linewidths )
492
496
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 )
496
501
col .set_color (colors )
497
502
self .ax .add_collection (col )
498
503
@@ -843,10 +848,13 @@ def on_mappable_changed(self, mappable):
843
848
self .set_clim (mappable .get_clim ())
844
849
self .update_normal (mappable )
845
850
846
- def add_lines (self , CS ):
851
+ def add_lines (self , CS , erase = True ):
847
852
'''
848
853
Add the lines from a non-filled
849
854
: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.
850
858
'''
851
859
if not isinstance (CS , contour .ContourSet ) or CS .filled :
852
860
raise ValueError ('add_lines is only for a ContourSet of lines' )
@@ -860,7 +868,8 @@ def add_lines(self, CS):
860
868
#tcolors = [col.get_colors()[0] for col in CS.collections]
861
869
#tlinewidths = [col.get_linewidth()[0] for lw in CS.collections]
862
870
#print 'tlinewidths:', tlinewidths
863
- ColorbarBase .add_lines (self , CS .levels , tcolors , tlinewidths )
871
+ ColorbarBase .add_lines (self , CS .levels , tcolors , tlinewidths ,
872
+ erase = erase )
864
873
865
874
def update_normal (self , mappable ):
866
875
'''
@@ -893,7 +902,7 @@ def update_bruteforce(self, mappable):
893
902
self .outline = None
894
903
self .patch = None
895
904
self .solids = None
896
- self .lines = None
905
+ self .lines = list ()
897
906
self .dividers = None
898
907
self .set_alpha (mappable .get_alpha ())
899
908
self .cmap = mappable .cmap
0 commit comments