@@ -682,7 +682,7 @@ class ContourSet(cm.ScalarMappable, ContourLabeler):
682
682
683
683
layers:
684
684
same as levels for line contours; half-way between
685
- levels for filled contours. See _process_colors method .
685
+ levels for filled contours. See :meth:` _process_colors` .
686
686
"""
687
687
def __init__ (self , ax , * args , ** kwargs ):
688
688
"""
@@ -1029,40 +1029,65 @@ def _contour_level_args(self, z, args):
1029
1029
raise ValueError ("Filled contours require at least 2 levels." )
1030
1030
1031
1031
def _process_levels (self ):
1032
- # Color mapping range (norm vmin, vmax) is based on levels.
1032
+ """
1033
+ Assign values to :attr:`layers` based on :attr:`levels`,
1034
+ adding extended layers as needed if contours are filled.
1035
+
1036
+ For line contours, layers simply coincide with levels;
1037
+ a line is a thin layer. No extended levels are needed
1038
+ with line contours.
1039
+ """
1040
+ # The following attributes are no longer needed, and
1041
+ # should be deprecated and removed to reduce confusion.
1033
1042
self .vmin = np .amin (self .levels )
1034
1043
self .vmax = np .amax (self .levels )
1035
- # Make a private _levels to include extended regions.
1044
+
1045
+ # Make a private _levels to include extended regions; we
1046
+ # want to leave the original levels attribute unchanged.
1047
+ # (Colorbar needs this even for line contours.)
1036
1048
self ._levels = list (self .levels )
1049
+
1050
+ if not self .filled :
1051
+ self .layers = self .levels
1052
+ return
1053
+
1037
1054
if self .extend in ('both' , 'min' ):
1038
1055
self ._levels .insert (0 , min (self .levels [0 ],self .zmin ) - 1 )
1039
1056
if self .extend in ('both' , 'max' ):
1040
1057
self ._levels .append (max (self .levels [- 1 ],self .zmax ) + 1 )
1041
1058
self ._levels = np .asarray (self ._levels )
1042
- if self .filled :
1043
- # layer values are mid-way between levels
1044
- self .layers = 0.5 * (self ._levels [:- 1 ] + self ._levels [1 :])
1045
- # ...except that extended layers must be outside the
1046
- # normed range:
1047
- if self .extend in ('both' , 'min' ):
1048
- self .layers [0 ] = - np .inf
1049
- if self .extend in ('both' , 'max' ):
1050
- self .layers [- 1 ] = np .inf
1051
- else :
1052
- self .layers = self .levels # contour: a line is a thin layer
1053
- # Use only original levels--no extended levels
1059
+
1060
+ # layer values are mid-way between levels
1061
+ self .layers = 0.5 * (self ._levels [:- 1 ] + self ._levels [1 :])
1062
+ # ...except that extended layers must be outside the
1063
+ # normed range:
1064
+ if self .extend in ('both' , 'min' ):
1065
+ self .layers [0 ] = - np .inf
1066
+ if self .extend in ('both' , 'max' ):
1067
+ self .layers [- 1 ] = np .inf
1054
1068
1055
1069
def _process_colors (self ):
1056
1070
"""
1057
1071
Color argument processing for contouring.
1058
1072
1059
- Note that we base the color mapping on the contour levels,
1060
- not on the actual range of the Z values. This means we
1061
- don't have to worry about bad values in Z, and we always have
1062
- the full dynamic range available for the selected levels.
1073
+ Note that we base the color mapping on the contour levels
1074
+ and layers, not on the actual range of the Z values. This
1075
+ means we don't have to worry about bad values in Z, and we
1076
+ always have the full dynamic range available for the selected
1077
+ levels.
1063
1078
1064
1079
The color is based on the midpoint of the layer, except for
1065
- an extended end layers.
1080
+ extended end layers. By default, the norm vmin and vmax
1081
+ are the extreme values of the non-extended levels. Hence,
1082
+ the layer color extremes are not the extreme values of
1083
+ the colormap itself, but approach those values as the number
1084
+ of levels increases. An advantage of this scheme is that
1085
+ line contours, when added to filled contours, take on
1086
+ colors that are consistent with those of the filled regions;
1087
+ for example, a contour line on the boundary between two
1088
+ regions will have a color intermediate between the those
1089
+ of the regions.
1090
+
1066
1091
"""
1067
1092
self .monochrome = self .cmap .monochrome
1068
1093
if self .colors is not None :
@@ -1079,12 +1104,11 @@ def _process_colors(self):
1079
1104
self .set_norm (colors .NoNorm ())
1080
1105
else :
1081
1106
self .cvalues = self .layers
1082
- if not self .norm . scaled ():
1083
- self .set_clim ( self . vmin , self . vmax )
1107
+ self .set_array ( self . levels )
1108
+ self .autoscale_None ( )
1084
1109
if self .extend in ('both' , 'max' , 'min' ):
1085
1110
self .norm .clip = False
1086
- self .set_array (self .layers ) # Required by colorbar, but not
1087
- # actually used.
1111
+
1088
1112
# self.tcolors are set by the "changed" method
1089
1113
1090
1114
def _process_linewidths (self ):
0 commit comments