@@ -864,22 +864,26 @@ def __init__(self, ax, *args, **kwargs):
864864 ncolors = len (self .levels )
865865 if self .filled :
866866 ncolors -= 1
867+ i0 = 0
867868
868869 # Handle the case where colors are given for the extended
869870 # parts of the contour.
870- given_colors = self .colors
871871 extend_min = self .extend in ['min' , 'both' ]
872872 extend_max = self .extend in ['max' , 'both' ]
873873 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.
876878 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 ])):
878881 use_set_under_over = True
879882 if extend_min :
880- given_colors = given_colors [1 :]
883+ i0 = 1
884+
885+ cmap = colors .ListedColormap (self .colors [i0 :None ], N = ncolors )
881886
882- cmap = colors .ListedColormap (given_colors , N = ncolors )
883887 if use_set_under_over :
884888 if extend_min :
885889 cmap .set_under (self .colors [0 ])
0 commit comments