holoviz / holoviz/hvplot

1D DataArray without coordinates defaults to a histogram

Open
#955 0 comments 0 reactions 0 assignees View on GitHub
interface: xarray
Dominant language
Python
Stars
1.4k
Forks
124
Avg merge
1d 18h
Merged PRs (30d)
1

Description

xarray defaults to a line plot on a 1D data array with no coordinates:

```python
import hvplot.xarray
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import xarray as xr

airtemps = xr.tutorial.open_dataset("air_temperature")
air = airtemps.air - 273.15
air.attrs = airtemps.air.attrs
air.attrs["units"] = "deg C"
air1d = air.isel(lat=10, lon=10)
air1d = air1d.drop_vars(["time"])
air1d.plot()
```

![image](https://user-images.githubusercontent.com/35924738/198546379-f0ea2d40-bd97-4983-b397-f79fc4e09341.png)

While `air1d.hvplot` defaults to a histogram:

![image](https://user-images.githubusercontent.com/35924738/198546462-90f4f288-d637-4892-9c38-a2e366ec394e.png)

And `air1d.hvplot.line()` raises a `DataError`:

```
DataError Traceback (most recent call last)
Cell In [52], line 1
----> 1 air1d.hvplot.line()

File ~/work/dev/hvplot/hvplot/plotting/core.py:331, in hvPlotTabular.line(self, x, y, **kwds)
256 def line(self, x=None, y=None, **kwds):
257 """
258 The `line` plot connects the points with a continous curve.
259
(...)
329 - Wiki: https://en.wikipedia.org/wiki/Line_chart
330 """
--> 331 return self(x, y, kind="line", **kwds)

File ~/work/dev/hvplot/hvplot/plotting/core.py:130, in hvPlotBase.__call__(self, x, y, kind, **kwds)
127 plot = self._get_converter(x, y, kind, **kwds)(kind, x, y)
128 return pn.panel(plot, **panel_dict)
--> 130 return self._get_converter(x, y, kind, **kwds)(kind, x, y)

File ~/work/dev/hvplot/hvplot/converter.py:1260, in HoloViewsConverter.__call__(self, kind, x, y)
1258 dataset = Dataset(data)
1259 dataset = dataset.redim(**self._redim)
-> 1260 obj = method(x, y)
1261 obj._dataset = dataset
1263 if self.crs and self.project:
1264 # Apply projection before rasterizing

File ~/work/dev/hvplot/hvplot/converter.py:1668, in HoloViewsConverter.line(self, x, y, data)
1666 print('>>> debug line', self.variables)
1667 # print(data.head())
-> 1668 return self.chart(Curve, x, y, data)

File ~/work/dev/hvplot/hvplot/converter.py:1634, in HoloViewsConverter.chart(self, element, x, y, data)
1632 return self.single_chart(element, x, y, data)
1633 elif x and y and len(y) == 1:
-> 1634 return self.single_chart(element, x, y[0], data)
1636 labelled = ['y' if self.invert else 'x'] if x != 'index' else []
1637 if self.value_label != 'value':

File ~/work/dev/hvplot/hvplot/converter.py:1554, in HoloViewsConverter.single_chart(self, element, x, y, data)
1552 chart = chart.layout() if self.subplots else chart.overlay(sort=False)
1553 else:
-> 1554 chart = element(data, kdims, vdims).relabel(**self._relabel)
1555 return (chart.redim(**self._redim)
1556 .opts(cur_opts, backend='bokeh')
1557 .opts(compat_opts, backend=self._backend_compat))

File ~/work/dev/holoviews/holoviews/element/selection.py:23, in SelectionIndexExpr.__init__(self, *args, **kwargs)
22 def __init__(self, *args, **kwargs):
---> 23 super().__init__(*args, **kwargs)
24 self._index_skip = False

File ~/work/dev/holoviews/holoviews/element/chart.py:51, in Chart.__init__(self, data, kdims, vdims, **params)
49 if len(params.get('kdims', [])) == self._max_kdim_count + 1:
50 self.param.warning('Chart elements should only be supplied a single kdim')
---> 51 super().__init__(data, **params)

File ~/work/dev/holoviews/holoviews/core/data/__init__.py:342, in Dataset.__init__(self, data, kdims, vdims, **kwargs)
340 (data, self.interface, dims, extra_kws) = initialized
341 super(Dataset, self).__init__(data, **dict(kwargs, **dict(dims, **extra_kws)))
--> 342 self.interface.validate(self, validate_vdims)
344 # Handle _pipeline property
345 if input_pipeline is None:

File ~/work/dev/holoviews/holoviews/core/data/pandas.py:165, in PandasInterface.validate(cls, dataset, vdims)
163 not_found = [d for d in dimensions if d not in cols]
164 if not_found:
--> 165 raise DataError("Supplied data does not contain specified "
166 "dimensions, the following dimensions were "
167 "not found: %s" % repr(not_found), cls)

DataError: Supplied data does not contain specified dimensions, the following dimensions were not found: ['index']

PandasInterface expects tabular data, for more information on supported datatypes see http://holoviews.org/user_guide/Tabular_Datasets.html
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.