hvplot
hvplot copied to clipboard
df.hvplot.bar() raises if hover_cols is provided while plotting multiple columns
In df.hvplot.bar(), the hover_cols parameter cannot be used if more than one column is being plotted. In fact, it fails any time a list of columns provided, even if that list contains only one element.
Example:
import pandas as pd
import hvplot.pandas
data = [
[10, 20, 'hello'],
[20, 10, 'goodbye']
]
df = pd.DataFrame(data, columns=['a', 'b', 'c'])
# Working
df.hvplot.bar(y='a', hover_cols=['c'])
# Broken
df.hvplot.bar(y=['a'], hover_cols=['c'])
df.hvplot.bar(y=['a', 'b'], hover_cols=['c'])
The error is:
DataError: Supplied data does not contain specified dimensions, the following dimensions were not found: ['c']
Click here for Traceback
---------------------------------------------------------------------------
DataError Traceback (most recent call last)
/tmp/ipykernel_1145701/4271017800.py in <module>
12
13 # Broken
---> 14 df.hvplot.bar(y=['a'], hover_cols=['c'])
15 df.hvplot.bar(y=['a', 'b'], hover_cols=['c'])
/groups/flyem/proj/cluster/miniforge/envs/flyem/lib/python3.7/site-packages/hvplot/plotting/core.py in bar(self, x, y, **kwds)
919 - Wiki: https://en.wikipedia.org/wiki/Bar_chart
920 """
--> 921 return self(x, y, kind="bar", **kwds)
922
923 def barh(self, x=None, y=None, **kwds):
/groups/flyem/proj/cluster/miniforge/envs/flyem/lib/python3.7/site-packages/hvplot/plotting/core.py in __call__(self, x, y, kind, **kwds)
128 return pn.panel(plot, **panel_dict)
129
--> 130 return self._get_converter(x, y, kind, **kwds)(kind, x, y)
131
132 def _get_converter(self, x=None, y=None, kind=None, **kwds):
/groups/flyem/proj/cluster/miniforge/envs/flyem/lib/python3.7/site-packages/hvplot/converter.py in __call__(self, kind, x, y)
1226 dataset = Dataset(data)
1227 dataset = dataset.redim(**self._redim)
-> 1228 obj = method(x, y)
1229 obj._dataset = dataset
1230
/groups/flyem/proj/cluster/miniforge/envs/flyem/lib/python3.7/site-packages/hvplot/converter.py in bar(self, x, y, data)
1697 y = y[0] if isinstance(y, (list, tuple)) else y
1698 return self.single_chart(Bars, x, y, data)
-> 1699 return self._category_plot(Bars, x, list(y), data)
1700
1701 def barh(self, x=None, y=None, data=None):
/groups/flyem/proj/cluster/miniforge/envs/flyem/lib/python3.7/site-packages/hvplot/converter.py in _category_plot(self, element, x, y, data)
1687 obj = Dataset(df, kdims, vdims).to(element, x).layout()
1688 else:
-> 1689 obj = element(df, kdims, vdims)
1690 return (obj.redim(**self._redim).relabel(**self._relabel)
1691 .apply(self._set_backends_opts, cur_opts=cur_opts, compat_opts=compat_opts))
/groups/flyem/proj/cluster/miniforge/envs/flyem/lib/python3.7/site-packages/holoviews/element/selection.py in __init__(self, *args, **kwargs)
21
22 def __init__(self, *args, **kwargs):
---> 23 super().__init__(*args, **kwargs)
24 self._index_skip = False
25
/groups/flyem/proj/cluster/miniforge/envs/flyem/lib/python3.7/site-packages/holoviews/element/chart.py in __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)
52
53 def __getitem__(self, index):
/groups/flyem/proj/cluster/miniforge/envs/flyem/lib/python3.7/site-packages/holoviews/core/data/__init__.py in __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)
343
344 # Handle _pipeline property
/groups/flyem/proj/cluster/miniforge/envs/flyem/lib/python3.7/site-packages/holoviews/core/data/pandas.py in validate(cls, dataset, vdims)
155 raise DataError("Supplied data does not contain specified "
156 "dimensions, the following dimensions were "
--> 157 "not found: %s" % repr(not_found), cls)
158
159
DataError: Supplied data does not contain specified dimensions, the following dimensions were not found: ['c']
PandasInterface expects tabular data, for more information on supported datatypes see http://holoviews.org/user_guide/Tabular_Datasets.html
Software versions
$ conda list | grep -E 'holoviews|hvplot|bokeh|cpython'
bokeh 2.4.3 py37h89c1867_0 conda-forge
holoviews 1.15.0 pyhd8ed1ab_0 conda-forge
hvplot 0.8.1 pyhd8ed1ab_0 conda-forge
jupyter_bokeh 3.0.2 pyhd8ed1ab_0 conda-forge
python 3.7.12 hb7a2778_100_cpython conda-forge
I can reproduce.