2D hvplot doesn't understand non-dimensioned coordinates
See original GitHub issueI’m not sure if this is a bug report, or a feature request. hvplot does not do what I expect when I try to interface with DataArrays with non-dimensioned coordinates.
Take this simple example dataset, representing a frame of camera data. I have the data both in terms of the row and column, as well as the pixel position in mm on the detector surface.
I should perhaps mention that I am learning XArray currently, so I might be doing something atypical… but this seems like the canonical way one is supposed to use non-dimensioned coordinates if I’m understanding the documentation correctly.
import xarray as xr, numpy as np, hvplot.xarray
ncols=5
nrows=5
pixel_size_mm = 2.0
cols = np.arange(ncols)
rows = np.arange(nrows)
x_position=xr.DataArray(cols*pixel_size_mm, dims=['col'], attrs={'units':'mm','long name':'Pixel X Position'})
y_position=xr.DataArray(cols*pixel_size_mm, dims=['row'], attrs={'units':'mm','long name':'Pixel Y Position'})
ROWS, COLS = np.meshgrid(rows, cols,copy=False)
values = np.sin(np.sqrt(ROWS**2 + COLS**2 )*np.pi/3) + 1.2 # Fun pattern
data = xr.DataArray(
values,
dims=['row','col',],
coords={
'row':rows,
'col':cols,
'xpix':x_position,
'ypix':y_position,
},
attrs={'units':'Photons'},
)
The following all do what I’d expect
data.hvplot('row')
data.hvplot('xpix')
data.hvplot('row','col')
However, the following fails:
data.hvplot('xpix','ypix')
I would expect something similar to what I get when using the xarray plotting interface:
data.plot(x='xpix',y='ypix')
I get this error:
ValueError Traceback (most recent call last) /var/folders/y2/y9fy_pn16gb66c78_q6jq97r000ww5/T/ipykernel_88550/4027993046.py in <module> ----> 1 data.hvplot(‘xpix’,‘ypix’)
~/miniconda3/envs/aspect/lib/python3.9/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/aspect/lib/python3.9/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/aspect/lib/python3.9/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/aspect/lib/python3.9/site-packages/holoviews/core/accessors.py in pipelined_call(*args, **kwargs) 45 46 try: —> 47 result = call(*args, **kwargs) 48 49 if not in_method:
~/miniconda3/envs/aspect/lib/python3.9/site-packages/holoviews/core/accessors.py in call(self, specs, **dimensions) 428 transform = self._create_expression_transform(kdims, vdims, list(renames.values())) 429 transforms = obj._transforms + [transform] –> 430 clone = obj.clone(data, kdims=kdims, vdims=vdims, transforms=transforms) 431 if self._obj.dimensions(label=‘name’) == clone.dimensions(label=‘name’): 432 # Ensure that plot_id is inherited as long as dimension
~/miniconda3/envs/aspect/lib/python3.9/site-packages/holoviews/element/raster.py in clone(self, data, shared_data, new_type, link, *args, **overrides) 427 ydensity=self.ydensity) 428 overrides = dict(sheet_params, **overrides) –> 429 return super(Image, self).clone(data, shared_data, new_type, link, 430 *args, **overrides) 431
~/miniconda3/envs/aspect/lib/python3.9/site-packages/holoviews/core/data/init.py in clone(self, data, shared_data, new_type, link, *args, **overrides) 1209 overrides[‘dataset’] = self.dataset 1210 -> 1211 return super(Dataset, self).clone( 1212 data, shared_data, new_type, *args, **overrides 1213 )
~/miniconda3/envs/aspect/lib/python3.9/site-packages/holoviews/core/dimension.py in clone(self, data, shared_data, new_type, link, *args, **overrides) 574 # Apply name mangling for __ attribute 575 pos_args = getattr(self, ‘_’ + type(self).name + ‘__pos_params’, []) –> 576 return clone_type(data, *args, **{k:v for k,v in settings.items() 577 if k not in pos_args}) 578
~/miniconda3/envs/aspect/lib/python3.9/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/aspect/lib/python3.9/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/aspect/lib/python3.9/site-packages/holoviews/core/sheetcoords.py in _boundsspec2slicespec(boundsspec, scs) 516 b_m,r_m = scs.sheet2matrix(r,b) 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()?
ValueError: cannot convert float NaN to integer
I have attached my conda environment here: env.txt
I’m running in MacOS 10.15.7.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Thanks @relativistic and sorry for the slow action on this. We’re trying to get holoviews 1.14.8 out this week with a fix.
I think we just need to push out a new release of HoloViews to fix that issue.