include max value in pcolormesh output when levels are requested#10954
include max value in pcolormesh output when levels are requested#10954JJFlorian wants to merge 6 commits intopydata:mainfrom
Conversation
|
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
|
Nice find — the The root cause is in def _build_discrete_cmap(cmap, levels, extend, filled):
...
new_cmap, cnorm = mpl.colors.from_levels_and_colors(levels, pal, extend=extend)
# BoundaryNorm uses half-open intervals [a, b), so values exactly at the
# last boundary are excluded. When there's no "over" extension, nudge the
# upper boundary so vmax is included in the last bin. (GH10911)
if extend in ("neither", "min"):
boundaries = cnorm.boundaries.copy()
boundaries[-1] = np.nextafter(boundaries[-1], np.inf)
cnorm = mpl.colors.BoundaryNorm(boundaries, cnorm.Ncmap)
...The condition checks |
Not the most elegant solution, but it works and I couldn't figure out another way of solving this for now. The
test_discrete_colormap_list_of_levelstest fails now, but I would say that it is safe to use numpy'sassert_array_almost_equal.If its not, I'll try to find another solution.