使用Hvp设置datashader=True时找不到聚合列类别

2024-09-27 00:13:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Hvplot根据数据所属的类别创建2个散点图。
因为数据点太多,所以我使用datashade。
当我不使用datashade时,我的绘图工作正常。

但是,当我在下面的代码中设置datashade=True时,会出现以下错误:

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.


示例代码:

# 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)

Tags: 数据sampleimportantruesizeasnp
1条回答
网友
1楼 · 发布于 2024-09-27 00:13:28

我认为它试图在“category”列上进行聚合,尽管事实上维度已按进行了分组。我已经在hvPlot中打开了this issue,希望很快能解决这个问题。目前,您可以使用以下解决方法:

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

相关问题 更多 >

    热门问题