hvplot
hvplot copied to clipboard
1D DataArray without coordinates defaults to a histogram
xarray defaults to a line plot on a 1D data array with no coordinates:
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()

While air1d.hvplot defaults to a histogram:

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