@@ -1283,26 +1283,38 @@ class TestContour(Common2dMixin, PlotTestCase):
1283
1283
1284
1284
plotfunc = staticmethod (xplt .contour )
1285
1285
1286
+ # matplotlib cmap.colors gives an rgbA ndarray
1287
+ # when seaborn is used, instead we get an rgb tuple
1288
+ @staticmethod
1289
+ def _color_as_tuple (c ):
1290
+ return tuple (c [:3 ])
1291
+
1286
1292
def test_colors (self ):
1287
- # matplotlib cmap.colors gives an rgbA ndarray
1288
- # when seaborn is used, instead we get an rgb tuple
1289
- def _color_as_tuple (c ):
1290
- return tuple (c [:3 ])
1291
1293
1292
1294
# with single color, we don't want rgb array
1293
1295
artist = self .plotmethod (colors = "k" )
1294
1296
assert artist .cmap .colors [0 ] == "k"
1295
1297
1296
1298
artist = self .plotmethod (colors = ["k" , "b" ])
1297
- assert _color_as_tuple (artist .cmap .colors [1 ]) == (0.0 , 0.0 , 1.0 )
1299
+ assert self . _color_as_tuple (artist .cmap .colors [1 ]) == (0.0 , 0.0 , 1.0 )
1298
1300
1299
1301
artist = self .darray .plot .contour (
1300
1302
levels = [- 0.5 , 0.0 , 0.5 , 1.0 ], colors = ["k" , "r" , "w" , "b" ]
1301
1303
)
1302
- assert _color_as_tuple (artist .cmap .colors [1 ]) == (1.0 , 0.0 , 0.0 )
1303
- assert _color_as_tuple (artist .cmap .colors [2 ]) == (1.0 , 1.0 , 1.0 )
1304
+ assert self ._color_as_tuple (artist .cmap .colors [1 ]) == (1.0 , 0.0 , 0.0 )
1305
+ assert self ._color_as_tuple (artist .cmap .colors [2 ]) == (1.0 , 1.0 , 1.0 )
1306
+ # the last color is now under "over"
1307
+ assert self ._color_as_tuple (artist .cmap ._rgba_over ) == (0.0 , 0.0 , 1.0 )
1308
+
1309
+ def test_colors_np_levels (self ):
1310
+
1311
+ # https://github.com/pydata/xarray/issues/3284
1312
+ levels = np .array ([- 0.5 , 0.0 , 0.5 , 1.0 ])
1313
+ artist = self .darray .plot .contour (levels = levels , colors = ["k" , "r" , "w" , "b" ])
1314
+ assert self ._color_as_tuple (artist .cmap .colors [1 ]) == (1.0 , 0.0 , 0.0 )
1315
+ assert self ._color_as_tuple (artist .cmap .colors [2 ]) == (1.0 , 1.0 , 1.0 )
1304
1316
# the last color is now under "over"
1305
- assert _color_as_tuple (artist .cmap ._rgba_over ) == (0.0 , 0.0 , 1.0 )
1317
+ assert self . _color_as_tuple (artist .cmap ._rgba_over ) == (0.0 , 0.0 , 1.0 )
1306
1318
1307
1319
def test_cmap_and_color_both (self ):
1308
1320
with pytest .raises (ValueError ):
0 commit comments