@@ -985,6 +985,22 @@ def contour(self, z,
985985used for colorbar functionality
986986"""
987987
988+ class ContourMappable (ScalarMappable ):
989+ """
990+ a class to allow contours to respond properly to change in cmaps, etc
991+ """
992+ def __init__ (self , levels , collections , norm = None , cmap = None ):
993+ ScalarMappable .__init__ (self , norm , cmap )
994+ self .levels = levels
995+ self .collections = collections
996+
997+ def changed (self ):
998+ colors = [ (tuple (rgba ),) for rgba in self .to_rgba (self .levels )]
999+ for color , collection in zip (colors , self .collections ):
1000+ collection .set_color (color )
1001+ ScalarMappable .changed (self )
1002+
1003+
9881004 if colors is not None and cmap is not None :
9891005 raise RuntimeError ('Either colors or cmap must be None' )
9901006 if origin is None : origin = rcParams ['image.origin' ]
@@ -1049,7 +1065,8 @@ def autolev(N):
10491065
10501066
10511067 Nlev = len (lev )
1052-
1068+ collections = []
1069+
10531070 if colors is not None :
10541071
10551072 if is_string_like (colors ):
@@ -1064,7 +1081,7 @@ def autolev(N):
10641081 tcolors = [(colorConverter .to_rgba (c , alpha ),) for c in colors ]
10651082 mappable = None
10661083 else :
1067- mappable = ScalarMappable ( cmap = cmap )
1084+ mappable = ContourMappable ( lev , collections , cmap = cmap )
10681085 mappable .set_array (z )
10691086 mappable .autoscale ()
10701087 tcolors = [ (tuple (rgba ),) for rgba in mappable .to_rgba (lev )]
@@ -1082,15 +1099,14 @@ def autolev(N):
10821099
10831100 args = zip (lev , tcolors , tlinewidths )
10841101
1085- levels = []
1086- collections = []
10871102
10881103 region = 0
1104+ levels = []
10891105 for level , color , width in args :
10901106 ntotal , nparts = _contour .GcInit1 (x , y , reg , triangle , region , z , level )
1091- np = zeros ((nparts ,), Int )
1092- xp = zeros ((ntotal , ), Float64 )
1093- yp = zeros ((ntotal ,), Float64 )
1107+ np = zeros ((nparts ,), 'l' )
1108+ xp = zeros ((ntotal , ), 'd' )
1109+ yp = zeros ((ntotal ,), 'd' )
10941110 nlist = _contour .GcTrace (np , xp , yp )
10951111 #print min(ravel(triangle)), max(ravel(triangle))
10961112 col = LineCollection (nlist , colors = color , linewidths = width )
0 commit comments