diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 177c2de7041..7f417648604 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -297,6 +297,10 @@ def _determine_cmap_params( levels = ticker.tick_values(vmin, vmax) vmin, vmax = levels[0], levels[-1] + # GH10911 + if calc_data.max() >= levels[-1]: + levels[-1] = np.nextafter(levels[-1], np.inf) + # GH3734 if vmin == vmax: vmin, vmax = mpl.ticker.LinearLocator(2).tick_values(vmin, vmax) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 40f950d246d..3d6706545d4 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -1209,8 +1209,8 @@ def test_discrete_colormap_list_of_levels(self) -> None: ]: for kind in ["imshow", "pcolormesh", "contourf", "contour"]: primitive = getattr(self.darray.plot, kind)(levels=levels) - assert_array_equal(levels, primitive.norm.boundaries) - assert max(levels) == primitive.norm.vmax + np.testing.assert_array_almost_equal(levels, primitive.norm.boundaries) + assert max(levels) <= primitive.norm.vmax assert min(levels) == primitive.norm.vmin if kind != "contour": assert extend == primitive.cmap.colorbar_extend