-
-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plotting with a discrete nonlinear colorbar assigns values to colors incorrectly #5966
Comments
I suspect some rounding issue is going on here: https://github.com/holoviz/holoviews/blob/main/holoviews/plotting/util.py#L954-L1000 Maybe it needs to use np.floor or np.ceil |
Just changing round for np.floor or np.ceil does not solve the issue. I do not understand completely how the colors are used. color_intervals() returns the input colormap but mapped to 255 values. Why does it have to be 255? I think being able to pass a custom norm argument could help fix this problem but it is not a valid option when plotting with bokeh backend and it does not work with matplotlib backend either (I posted an issue a while ago here). |
Increasing the default value of N in color_intervals() from 255 to 1000 or 10000 works to solve the issue. Basically it is increasing the resolution of the colormap. But it will be dependent on the color_levels provided, if this increased resolution is enough to catch the precision needed. So I think it is still a sub-optimal solution. |
The "fix" of increasing N does nothing if using matplotlib backend. Again, this may be solved by being able to pass norm to the plotting call, but there is a problem. It could be solved by adding:
to the definition of init_artists inside class QuadMeshPlot in line 192 in holoviews/plotting/mpl/raster.py, in the same way this norm condition is already present in line 594 in /holoviews/plotting/mpl/element.py |
Thanks for investigating. I think it's still worthwhile to deploy a fix for bokeh. I'd support adding support for norm to mpl, maybe as a |
In my case the mpl backend is working correctly when passing norm to the plot call directly or inside .opts() (after applying the fix that I just posted above). Am I missing something? |
Passing norm to opts is enough (at least for me). |
Updated! |
The fix regarding passing 'norm' when plotting a quadmesh with matplotlib backend has been merged into the main branch. The issue on how to handle the same problem with bokeh remains. I still don't know what the best approach could be. |
I think this should have been fixed by #4898 I will close this issue, but you are welcome to reopen it if you don't think the problem is solved. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
ALL software version info
Name Version Build Channel
holoviews 1.17.1 pyhd8ed1ab_0 conda-forge
hvplot 0.8.4 pyhd8ed1ab_1 conda-forge
bokeh 3.2.2 pyhd8ed1ab_0 conda-forge
xarray 2023.9.0 pyhd8ed1ab_0 conda-forge
python 3.11.5 hab00c5b_0_cpython conda-forge
spyder 5.4.5 py311h38be061_0 conda-forge
spyder-kernels 2.4.4 unix_pyh707e725_0 conda-forge
Description of expected behavior and the observed behavior
I am trying to plot a QuadMesh with a discrete nonlinear colorbar. I have found help from several posts in the discourse and GitHub but mainly this one. When plotting by passing a discrete list of colors (cmap) and levels (color_levels), a plot is produced which looks correct at first glance. But, on closer inspection or when the data is more challenging (more extreme values or very irregular color ranges) some values on the verge of a color level are incorrectly assign to a different color.
Complete, minimal, self-contained example code that reproduces the issue
In this example, you can also change the extreme values in BOUNDS to be more extreme and the problem is more notorious.
Screenshots or screencasts of the bug in action
See example of a value that should be colored yellow but it is green.
The text was updated successfully, but these errors were encountered: