MCPcopy
hub / github.com/pydata/xarray / test_contourf_cmap_set

Method test_contourf_cmap_set

xarray/tests/test_plot.py:453–480  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

451 x.T.plot.pcolormesh()
452
453 def test_contourf_cmap_set(self) -> None:
454 a = DataArray(easy_array((4, 4)), dims=["z", "time"])
455
456 cmap_expected = mpl.colormaps["viridis"]
457
458 # use copy to ensure cmap is not changed by contourf()
459 # Set vmin and vmax so that _build_discrete_colormap is called with
460 # extend='both'. extend is passed to
461 # mpl.colors.from_levels_and_colors(), which returns a result with
462 # sensible under and over values if extend='both', but not if
463 # extend='neither' (but if extend='neither' the under and over values
464 # would not be used because the data would all be within the plotted
465 # range)
466 pl = a.plot.contourf(cmap=copy(cmap_expected), vmin=0.1, vmax=0.9)
467
468 # check the set_bad color
469 cmap = pl.cmap
470 assert cmap is not None
471 assert_array_equal(
472 cmap(np.ma.masked_invalid([np.nan]))[0],
473 cmap_expected(np.ma.masked_invalid([np.nan]))[0],
474 )
475
476 # check the set_under color
477 assert cmap(-np.inf) == cmap_expected(-np.inf)
478
479 # check the set_over color
480 assert cmap(np.inf) == cmap_expected(np.inf)
481
482 def test_contourf_cmap_set_with_bad_under_over(self) -> None:
483 a = DataArray(easy_array((4, 4)), dims=["z", "time"])

Callers

nothing calls this directly

Calls 3

DataArrayClass · 0.90
easy_arrayFunction · 0.85
contourfMethod · 0.80

Tested by

no test coverage detected