Holoviews 图表不更新小部件选择
Holoviews charts not updating on widget selection
我从一个单独的 post 复制了下面的代码,以创建根据选择更新绘图的小部件:
# import libraries
import numpy as np
import pandas as pd
import hvplot
import hvplot.pandas
import holoviews as hv
hv.extension('bokeh', logo=False)
import panel as pn
# create sample data
df = pd.DataFrame({
'col1': np.random.rand(30),
'col2': np.random.normal(size=30),
'category_col': np.random.choice(['category1', 'category2'], size=30)
})
# create widget to select category
category = pn.widgets.Select(options=['category1', 'category2'])
# function that returns a plot depending on the category selected
@pn.depends(category)
def get_plot(category):
df_selected = df[df['category_col'] == category]
plot = df_selected.hvplot.scatter(x='col1', y='col2')
return plot
# show dashboard with selection widget and dynamic plot
pn.Column(
pn.Row(category),
get_plot,
)
# get value of current selected category
category.value
但是,对我来说,选择后图表不会更新。有谁知道这里发生了什么?我正在尝试在本地机器上的 Jupyter Lab 笔记本中执行此操作,没有服务器。我是 运行 这些库的以下版本:
全息视图:1.13.3
hvplot:0.6.0
面板:0.9.7
任何见解将不胜感激!
亲切的问候
该代码在使用相同版本的经典笔记本中对我来说工作正常(全息图:1.13.3 hvplot:0.6.0 面板:0.9.7)。您是否安装了 JupyterLab 扩展? https://panel.holoviz.org/#installation
我从一个单独的 post 复制了下面的代码,以创建根据选择更新绘图的小部件:
# import libraries
import numpy as np
import pandas as pd
import hvplot
import hvplot.pandas
import holoviews as hv
hv.extension('bokeh', logo=False)
import panel as pn
# create sample data
df = pd.DataFrame({
'col1': np.random.rand(30),
'col2': np.random.normal(size=30),
'category_col': np.random.choice(['category1', 'category2'], size=30)
})
# create widget to select category
category = pn.widgets.Select(options=['category1', 'category2'])
# function that returns a plot depending on the category selected
@pn.depends(category)
def get_plot(category):
df_selected = df[df['category_col'] == category]
plot = df_selected.hvplot.scatter(x='col1', y='col2')
return plot
# show dashboard with selection widget and dynamic plot
pn.Column(
pn.Row(category),
get_plot,
)
# get value of current selected category
category.value
但是,对我来说,选择后图表不会更新。有谁知道这里发生了什么?我正在尝试在本地机器上的 Jupyter Lab 笔记本中执行此操作,没有服务器。我是 运行 这些库的以下版本:
全息视图:1.13.3 hvplot:0.6.0 面板:0.9.7
任何见解将不胜感激!
亲切的问候
该代码在使用相同版本的经典笔记本中对我来说工作正常(全息图:1.13.3 hvplot:0.6.0 面板:0.9.7)。您是否安装了 JupyterLab 扩展? https://panel.holoviz.org/#installation