hvplot
hvplot copied to clipboard
Cannot use hv.dim() to declare the `c` color parameter of a scatter plot
I can't declare the column I want to use to color (c=) the points of a scatter plot with hv.dim(). Note that it's working well for the size (not shown here).
import hvplot.pandas
import numpy as np
import pandas as pd
import holoviews as hv
df = pd.DataFrame(np.random.rand(50, 4)*10, columns=['a', 'b', 'c', 'd'])
df.hvplot.scatter(x='a', y='b', size=hv.dim('c'), c=hv.dim('d'))
Traceback:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/var/folders/c9/s6_8wl553ql93tjgvmbmsn5h0000gp/T/ipykernel_45265/1448612498.py in <module>
7 df = pd.DataFrame(np.random.rand(50, 4)*10, columns=['a', 'b', 'c', 'd'])
8
----> 9 df.hvplot.scatter(x='a', y='b', size=hv.dim('c'), c=hv.dim('d'))
~/work/dev/hvplot/hvplot/plotting/core.py in scatter(self, x, y, **kwds)
197 The HoloViews representation of the plot.
198 """
--> 199 return self(x, y, kind='scatter', **kwds)
200
201 def area(self, x=None, y=None, y2=None, stacked=True, **kwds):
~/work/dev/hvplot/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):
~/work/dev/hvplot/hvplot/plotting/core.py in _get_converter(self, x, y, kind, **kwds)
85 kind = kind or params.pop('kind', None)
86 return HoloViewsConverter(
---> 87 self._data, x, y, kind=kind, **params
88 )
89
~/work/dev/hvplot/hvplot/converter.py in __init__(self, data, x, y, kind, by, use_index, group_label, value_label, backlog, persist, use_dask, crs, fields, groupby, dynamic, grid, legend, rot, title, xlim, ylim, clim, symmetric, logx, logy, loglog, hover, subplots, label, invert, stacked, colorbar, datashade, rasterize, row, col, figsize, debug, framewise, aggregator, projection, global_extent, geo, precompute, flip_xaxis, flip_yaxis, dynspread, hover_cols, x_sampling, y_sampling, project, tools, attr_labels, coastline, tiles, sort_date, check_symmetric_max, transforms, stream, cnorm, features, backends, **kwds)
796 plot_opts[plotwd] = kwds.pop(plotwd)
797
--> 798 self._style_opts, plot_opts, kwds = self._process_style(kwds, plot_opts)
799
800 for axis_name in ['xaxis', 'yaxis']:
~/work/dev/hvplot/hvplot/converter.py in _process_style(self, kwds, plot_opts)
1330 if not isinstance(color, list) and color in self.variables and \
1331 'c' in self._kind_options.get(kind, []):
-> 1332 if self.data[color].dtype.kind in 'OSU':
1333 cmap = cmap or self._default_cmaps['categorical']
1334 else:
~/miniconda3/envs/hvplot-dev37/lib/python3.7/site-packages/pandas/core/frame.py in __getitem__(self, key)
3418 def __getitem__(self, key):
3419 key = lib.item_from_zerodim(key)
-> 3420 key = com.apply_if_callable(key, self)
3421
3422 if is_hashable(key):
~/miniconda3/envs/hvplot-dev37/lib/python3.7/site-packages/pandas/core/common.py in apply_if_callable(maybe_callable, obj, **kwargs)
356 """
357 if callable(maybe_callable):
--> 358 return maybe_callable(obj, **kwargs)
359
360 return maybe_callable
~/miniconda3/envs/hvplot-dev37/lib/python3.7/site-packages/holoviews/util/transform.py in __call__(self, *args, **kwargs)
265 "Only methods accessed via namspaces, "
266 "e.g. dim(...).df or dim(...).xr), "
--> 267 "can be called. " % self)
268 op = self.ops[-1]
269 if op['fn'] == 'str':
ValueError: Cannot call method on dim('d') expression. Only methods accessed via namspaces, e.g. dim(...).df or dim(...).xr), can be called.