@@ -864,22 +864,26 @@ def __init__(self, ax, *args, **kwargs):
864
864
ncolors = len (self .levels )
865
865
if self .filled :
866
866
ncolors -= 1
867
+ i0 = 0
867
868
868
869
# Handle the case where colors are given for the extended
869
870
# parts of the contour.
870
- given_colors = self .colors
871
871
extend_min = self .extend in ['min' , 'both' ]
872
872
extend_max = self .extend in ['max' , 'both' ]
873
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.
874
+ # if we are extending the lower end, and we've been given enough
875
+ # colors then skip the first color in the resulting cmap. For the
876
+ # extend_max case we don't need to worry about passing more colors
877
+ # than ncolors as ListedColormap will clip.
876
878
total_levels = ncolors + int (extend_min ) + int (extend_max )
877
- if len (self .colors ) == total_levels and any ([extend_min , extend_max ]):
879
+ if (len (self .colors ) == total_levels and
880
+ any ([extend_min , extend_max ])):
878
881
use_set_under_over = True
879
882
if extend_min :
880
- given_colors = given_colors [1 :]
883
+ i0 = 1
884
+
885
+ cmap = colors .ListedColormap (self .colors [i0 :None ], N = ncolors )
881
886
882
- cmap = colors .ListedColormap (given_colors , N = ncolors )
883
887
if use_set_under_over :
884
888
if extend_min :
885
889
cmap .set_under (self .colors [0 ])
0 commit comments