gpt4 book ai didi

javascript - 使用 TapTool 更新 Bokeh 圈的选择索引

转载 作者:行者123 更新时间:2023-12-03 01:45:51 25 4
gpt4 key购买 nike

我在 TapTool 上使用 CustomJS 回调时遇到问题。我想在点击后强制选择 50 个点。因此,我做了一个 JavaScript 回调来修改数据源中选择的索引列表,并应该更新绘图。我可以通过控制台看到数据源已更新,但绘图未更新。

我已经根据文档示例制作了一个测试版本

https://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html

但它也不起作用。是因为选择更改时更新绘图的方式不同吗?

这是我制作的测试版本:

from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource, Slider
from bokeh.plotting import Figure, output_file, show

output_notebook()

x = [x*0.005 for x in range(0, 200)]
y = x

source = ColumnDataSource(data=dict(x=x, y=y))

plot = Figure(plot_width=400, plot_height=400)
plot.circle('x', 'y', source=source, line_width=3, line_alpha=0.6)

callback = CustomJS(args=dict(source=source), code="""
var l_selected=source.selected;
var indices = l_selected['1d'].indices;
if(indices.length <= 1) {
var new_indices = Array.from(new Array(50), (x,i) => i + indices[0]);
l_selected['1d'].indices=new_indices;
}
source.selected=l_selected;
console.log(source.selected)
source.change.emit();
""")


slider = Slider(start=0.1, end=4, value=1, step=.1, title="power")
slider.js_on_change('value', callback)

plot.add_tools(TapTool(callback=callback))

layout = column(slider, plot)

show(layout)

我不知道它是否有用,但我正在使用 0.12.16 版本的 Bokeh,并且我正在尝试使其在 Jupyter 笔记本中工作

最佳答案

Seb在评论中给出了答案。自 bokeh 0.12.15 source.selected['1d'] 变为 source.selected.indices

关于javascript - 使用 TapTool 更新 Bokeh 圈的选择索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50645356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com