From a32bd7dc9740afd051750c659753b9dead228b72 Mon Sep 17 00:00:00 2001 From: knappersfy Date: Fri, 28 Nov 2025 13:30:05 +0100 Subject: [PATCH 1/5] increase last value of levels --- xarray/plot/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 177c2de7041..2171c855feb 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) From eba3a8386b1b40450b5a1cd0a9661584e98a37e1 Mon Sep 17 00:00:00 2001 From: knappersfy Date: Fri, 28 Nov 2025 14:38:12 +0100 Subject: [PATCH 2/5] change test to adapt to new situation --- xarray/tests/test_plot.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 40f950d246d..85682497f21 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -1209,9 +1209,12 @@ 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) + + np.testing.assert_allclose(max(levels), primitive.norm.vmax, rtol=0, atol=1e-12) + assert max(levels) <= primitive.norm.vmax assert min(levels) == primitive.norm.vmin + if kind != "contour": assert extend == primitive.cmap.colorbar_extend else: From 9d2227c99ebf1488e9e964039652b7dcdd54e6aa Mon Sep 17 00:00:00 2001 From: knappersfy Date: Fri, 28 Nov 2025 14:39:27 +0100 Subject: [PATCH 3/5] better change of tets --- xarray/tests/test_plot.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 85682497f21..166a8374f03 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -1210,8 +1210,6 @@ def test_discrete_colormap_list_of_levels(self) -> None: for kind in ["imshow", "pcolormesh", "contourf", "contour"]: primitive = getattr(self.darray.plot, kind)(levels=levels) np.testing.assert_array_almost_equal(levels, primitive.norm.boundaries) - - np.testing.assert_allclose(max(levels), primitive.norm.vmax, rtol=0, atol=1e-12) assert max(levels) <= primitive.norm.vmax assert min(levels) == primitive.norm.vmin From 43f8c6f832dbef56e7afea47afde1c6932b7af7f Mon Sep 17 00:00:00 2001 From: knappersfy Date: Fri, 28 Nov 2025 14:39:52 +0100 Subject: [PATCH 4/5] rm added line --- xarray/tests/test_plot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 166a8374f03..3d6706545d4 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -1212,7 +1212,6 @@ def test_discrete_colormap_list_of_levels(self) -> None: 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 else: From 9ce536f10333761338c68f7b679f6512f04ac2fd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 28 Nov 2025 13:41:59 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/plot/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 2171c855feb..7f417648604 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -297,7 +297,7 @@ def _determine_cmap_params( levels = ticker.tick_values(vmin, vmax) vmin, vmax = levels[0], levels[-1] - #GH10911 + # GH10911 if calc_data.max() >= levels[-1]: levels[-1] = np.nextafter(levels[-1], np.inf)