Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading