Aggregation column category not found - when I set datashader = True with Hvplot

535 Views Asked by At

I'm using Hvplot to create 2 scatterplots based on the category the data falls in.
Since there are so many datapoints, I'm using datashade.
My plot works fine when I don't use datashade.

However when I set datashade=True in my code below I get the following error:

WARNING:param.dynamic_operation: Callable raised "ValueError('Aggregation column category not found on :Scatter
[col1] (col2) element. Ensure the aggregator references an existing dimension.',)". Invoked as dynamic_operation(height=300, scale=1.0, width=1200, x_range=None, y_range=None)

ValueError: Aggregation column category not found on :Scatter [col1] (col2) element. Ensure the aggregator references an existing dimension.


Example code:

# import libraries
import numpy as np
import pandas as pd

import hvplot
import hvplot.pandas

import holoviews as hv
hv.extension('bokeh')

from holoviews.operation.datashader import datashade

# create some sample data
sample_scatter1 = np.random.normal(loc=0.0, size=50)
sample_scatter2 = np.random.normal(loc=300., size=50)
sample_category = np.random.choice(2, size=50)

demo_df = pd.DataFrame({
    'col1': sample_scatter1,
    'col2': sample_scatter2,
    'category': sample_category,
})

# this works fine if I would set datashade=False, but with datashade=True it gives an error
demo_df.hvplot(
    kind='scatter', 
    x='col1', y='col2', 
    by='category', 
    subplots=True, 
    width=1200, 
    datashade=True
).cols(1)
1

There are 1 best solutions below

0
On BEST ANSWER

I think it's trying to aggregate on the 'category' column, despite the fact that dimension has been grouped by. I've opened this issue in hvPlot to hopefully address soon. For now you can use this workaround:

demo_df.hvplot(
    kind='scatter', 
    x='col1', y='col2', 
    groupby='category',
    width=1200, 
    datashade=True
).layout().cols(1)