hvplot
hvplot copied to clipboard
Image plot raises `ValueError: cannot convert float NaN to integer` with the air dataset
import xarray as xr
import hvplot.xarray # v0.7.3
airtemps = xr.tutorial.open_dataset("air_temperature")
air = airtemps.air # 3D DataArray
air.isel(time=0).hvplot() # runs fine and returns an Image plot
air.isel(lat=0).hvplot() # raises a ValueError!
air.isel(lon=0).hvplot() # raises a ValueError!
air.isel(lon=0).plot() # runs fine with the xarray plot method
Warning raised:
/Users/mliquet/miniconda3/envs/holoviz37/lib/python3.7/site-packages/holoviews/core/util.py:2079: RuntimeWarning: invalid value encountered in true_divide
return length/diff
Traceback:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-3f937c8403fa> in <module>
4 airtemps = xr.tutorial.open_dataset("air_temperature")
5 air = airtemps.air
----> 6 air.isel(lat=0).hvplot.image()
~/miniconda3/envs/holoviz37/lib/python3.7/site-packages/hvplot/plotting/core.py in image(self, x, y, z, colorbar, **kwds)
646 The HoloViews representation of the plot.
647 """
--> 648 return self(x, y, z=z, kind='image', colorbar=colorbar, **kwds)
649
650 def rgb(self, x=None, y=None, z=None, bands=None, **kwds):
~/miniconda3/envs/holoviz37/lib/python3.7/site-packages/hvplot/plotting/core.py in __call__(self, x, y, kind, **kwds)
77 return pn.panel(plot, **panel_dict)
78
---> 79 return self._get_converter(x, y, kind, **kwds)(kind, x, y)
80
81 def _get_converter(self, x=None, y=None, kind=None, **kwds):
~/miniconda3/envs/holoviz37/lib/python3.7/site-packages/hvplot/converter.py in __call__(self, kind, x, y)
1135 dataset = Dataset(data)
1136 dataset = dataset.redim(**self._redim)
-> 1137 obj = method(x, y)
1138 obj._dataset = dataset
1139
~/miniconda3/envs/holoviz37/lib/python3.7/site-packages/hvplot/converter.py in image(self, x, y, z, data)
1857 element = self._get_element('image')
1858 if self.geo: params['crs'] = self.crs
-> 1859 return element(data, [x, y], z, **params).redim(**redim).opts(**opts)
1860
1861 def rgb(self, x=None, y=None, z=None, data=None):
~/miniconda3/envs/holoviz37/lib/python3.7/site-packages/holoviews/element/raster.py in __init__(self, data, kdims, vdims, bounds, extents, xdensity, ydensity, rtol, **params)
324 xdensity = xdensity if xdensity else util.compute_density(l, r, dim1, self._time_unit)
325 ydensity = ydensity if ydensity else util.compute_density(b, t, dim2, self._time_unit)
--> 326 SheetCoordinateSystem.__init__(self, bounds, xdensity, ydensity)
327 if non_finite:
328 self.bounds = BoundingBox(points=((np.nan, np.nan), (np.nan, np.nan)))
~/miniconda3/envs/holoviz37/lib/python3.7/site-packages/holoviews/core/sheetcoords.py in __init__(self, bounds, xdensity, ydensity)
164 self.lbrt = np.array(bounds.lbrt())
165
--> 166 r1,r2,c1,c2 = Slice._boundsspec2slicespec(self.lbrt,self)
167 self.__shape = (r2-r1,c2-c1)
168
~/miniconda3/envs/holoviz37/lib/python3.7/site-packages/holoviews/core/sheetcoords.py in _boundsspec2slicespec(boundsspec, scs)
517
518 l_idx = int(np.ceil(l_m-0.5))
--> 519 t_idx = int(np.ceil(t_m-0.5))
520 # CBENHANCEMENT: Python 2.6's math.trunc()?
521 r_idx = int(np.floor(r_m+0.5))
ValueError: cannot convert float NaN to integer
I ran into the same issue with a gray image