holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 402 forks source link

hv.Image warns about rtol #3465

Closed flothesof closed 5 years ago

flothesof commented 5 years ago

Hey there, I'm trying to plot functions using the hv.Image element. I keep getting this warning:

WARNING:root:Image01077: Image dimension(s) x and y are not evenly sampled to relative tolerance of 0.001. Please use the QuadMesh element for irregularly sampled data or set a higher tolerance on hv.config.image_rtol or the rtol parameter in the Image constructor.

Here's my sample code:

import numpy as np
import holoviews as hv
hv.extension('bokeh')

x = np.arange(-1, 1, 0.1)
y = np.arange(-1, 1, 0.1)
X, Y = np.meshgrid(x, y)
Z = np.sqrt(X**2 + Y**2) * np.cos(X)

hv.Image((X, Y, Z))

I tried following the recommandations about rtol. But even something like hv.Image((X, Y, Z), rtol=1.) will still give the warning, which I don't understand since my data is equally spaced.

As a side note, this works nicely with QuadMesh (hat-tip to the good warning!), but QuadMesh with the Bokeh backend displays gray cell borders which I don't want.

Thanks for your help.

Regards, Florian

philippjfr commented 5 years ago

Oh, the warning is actually wrong in this case, Image is not meant to support 2D coordinate arrays at all. So the reason for the warning is because it's trying to find the sampling on a flattened version of the 2D coordinate arrays which are obviously not equally spaced.

michaelaye commented 2 years ago

How does Image determine if it's okay to be used? I have an xarray with one dimension having slightly non-equidistant values, and I still get an Image by default, with above warning though (the spectral coordinate is not strictly equidistant):

image

image

Versions:

jbednar commented 2 years ago

arr.hvplot.image() (which appears to be the default hvplot selectshere) checks to see if the coordinates explicitly encoded match the implicit coordinates computed by assuming equally spaced bins over the x and y ranges as Image rendering requires. If they match to within rtol, great!; otherwise you get a warning. If rtol is nearly ok and just needs to be a little more relaxed, feel free to increase rtol, but usually what it means is that an Image is inappropriate and you should use arr.hvplot.quadmesh() instead.

swawa commented 2 years ago

hvplot.quadmesh() is NOT an adequad solution. It results in a ugly aliasing; see multiple comments: https://stackoverflow.com/questions/72448687/python-using-hvplot-quadmesh-for-xarray-data-shows-blended-colors-in-a-plot https://discourse.holoviz.org/t/how-to-stop-param-image-warning/2934 https://discourse.holoviz.org/t/hvplot-reporting-inconsistent-chunks-on-xarray-dataarray/1690

michaelaye commented 2 years ago

hvplot.quadmesh() is NOT an adequad solution. It results in a ugly aliasing; see multiple comments: https://stackoverflow.com/questions/72448687/python-using-hvplot-quadmesh-for-xarray-data-shows-blended-colors-in-a-plot https://discourse.holoviz.org/t/how-to-stop-param-image-warning/2934 https://discourse.holoviz.org/t/hvplot-reporting-inconsistent-chunks-on-xarray-dataarray/1690

your links are broken?

swawa commented 2 years ago

now the links should work. I edited the post