Search code examples
python-3.xmatplotlibcolormap

For discrete colormaps, which edge is closed or open?


say I have a colorbar with ticks like this -

enter image description here

In my case I've used linespace to define the ticks and used mpl.color.BoundaryNorm to create the norm.

If I know that large parts of my dataset include zero, how do I know if the zeros are in -10 -> 0 or 0 -> 10? Is there a way to check this?

I'm assuming practically it comes down to the machine precision of the numbers given they're float values in my case but are the boundary thresholds given somewhere?.


Solution

  • mpl.color.BoundaryNorm internally uses numpy.digitize with default values, so the condition is bins[i-1] <= x < bins[i], i.e. the lower edge is closed and the upper edge is open.