@@ -864,7 +864,28 @@ def __init__(self, ax, *args, **kwargs):
864
864
ncolors = len (self .levels )
865
865
if self .filled :
866
866
ncolors -= 1
867
- cmap = colors .ListedColormap (self .colors , N = ncolors )
867
+
868
+ # Handle the case where colors are given for the extended
869
+ # parts of the contour.
870
+ given_colors = self .colors
871
+ extend_min = self .extend in ['min' , 'both' ]
872
+ extend_max = self .extend in ['max' , 'both' ]
873
+ use_set_under_over = False
874
+ # if we are extending the lower end, and we've been given enough colors
875
+ # then skip the first color in the resulting cmap.
876
+ total_levels = ncolors + int (extend_min ) + int (extend_max )
877
+ if len (self .colors ) == total_levels and any ([extend_min , extend_max ]):
878
+ use_set_under_over = True
879
+ if extend_min :
880
+ given_colors = given_colors [1 :]
881
+
882
+ cmap = colors .ListedColormap (given_colors , N = ncolors )
883
+ if use_set_under_over :
884
+ if extend_min :
885
+ cmap .set_under (self .colors [0 ])
886
+ if extend_max :
887
+ cmap .set_over (self .colors [- 1 ])
888
+
868
889
if self .filled :
869
890
self .collections = cbook .silent_list ('mcoll.PathCollection' )
870
891
else :
@@ -1172,16 +1193,16 @@ def _process_levels(self):
1172
1193
# (Colorbar needs this even for line contours.)
1173
1194
self ._levels = list (self .levels )
1174
1195
1175
- if not self .filled :
1176
- self .layers = self .levels
1177
- return
1178
-
1179
1196
if self .extend in ('both' , 'min' ):
1180
1197
self ._levels .insert (0 , min (self .levels [0 ], self .zmin ) - 1 )
1181
1198
if self .extend in ('both' , 'max' ):
1182
1199
self ._levels .append (max (self .levels [- 1 ], self .zmax ) + 1 )
1183
1200
self ._levels = np .asarray (self ._levels )
1184
1201
1202
+ if not self .filled :
1203
+ self .layers = self .levels
1204
+ return
1205
+
1185
1206
# layer values are mid-way between levels
1186
1207
self .layers = 0.5 * (self ._levels [:- 1 ] + self ._levels [1 :])
1187
1208
# ...except that extended layers must be outside the
@@ -1526,9 +1547,7 @@ def _check_xyz(self, args, kwargs):
1526
1547
if y .shape != z .shape :
1527
1548
raise TypeError ("Shape of y does not match that of z: found "
1528
1549
"{0} instead of {1}." .format (y .shape , z .shape ))
1529
-
1530
1550
else :
1531
-
1532
1551
raise TypeError ("Inputs x and y must be 1D or 2D." )
1533
1552
1534
1553
return x , y , z
0 commit comments