@@ -168,21 +168,22 @@ def test_given_colors_levels_and_extends():
168
168
levels = [2 , 4 , 8 , 10 ]
169
169
170
170
for i , ax in enumerate (axes .flatten ()):
171
- plt .sca (ax )
172
-
173
171
filled = i % 2 == 0.
174
172
extend = ['neither' , 'min' , 'max' , 'both' ][i // 2 ]
175
173
176
174
if filled :
177
- last_color = - 1 if extend in ['min' , 'max' ] else None
178
- plt .contourf (data , colors = colors [:last_color ], levels = levels ,
179
- extend = extend )
175
+ # If filled, we have 3 colors with no extension,
176
+ # 4 colors with one extension, and 5 colors with both extensions
177
+ first_color = 1 if extend in ['max' , 'neither' ] else None
178
+ last_color = - 1 if extend in ['min' , 'neither' ] else None
179
+ c = ax .contourf (data , colors = colors [first_color :last_color ],
180
+ levels = levels , extend = extend )
180
181
else :
181
- last_level = - 1 if extend == 'both' else None
182
- plt .contour (data , colors = colors , levels = levels [: last_level ],
183
- extend = extend )
182
+ # If not filled, we have 4 levels and 4 colors
183
+ c = ax .contour (data , colors = colors [: - 1 ],
184
+ levels = levels , extend = extend )
184
185
185
- plt .colorbar ()
186
+ plt .colorbar (c , ax = ax )
186
187
187
188
188
189
@image_comparison (baseline_images = ['contour_datetime_axis' ],
0 commit comments