gpt4 book ai didi

Bokeh 动态改变 BoxAnnotation

转载 作者:行者123 更新时间:2023-12-04 10:24:17 26 4
gpt4 key购买 nike

是否可以在 IPython 的交互功能中更新 Bokeh 图的渲染。我有如下代码:

x = [0, 1, 2, 3, 4]
y = [0, 1, 2, 3, 4]
source = ColumnDataSource(data=dict(x=x, y=y)
f = figure()
f.line(x, y, source=source)
show(f)

def update_func(selected_data):
source.data['y'] = ...
source.push_notebook()
<here I would like to add BoxAnnotation to figure f, and rerender it>

interactive(update_func, selected_data=[0,1,2])

最佳答案

截至 Bokeh 0.11 push_notebook函数现在可以更新任意 Bokeh 模型对象。因此,只需设置/更新框注释上的属性并调用 push_notebook .您的代码将类似于:

x = [0, 1, 2, 3, 4]
y = [0, 1, 2, 3, 4]
source = ColumnDataSource(data=dict(x=x, y=y)
f = figure()
f.line(x, y, source=source)
show(f)

def update_func(selected_data):
source.data['y'] = ...
# update box annotation (or any other properties) here
push_notebook() # note, just a function, not a method on "source"

interactive(update_func, selected_data=[0,1,2])

你可以在这里看到一些howto notebooks:

https://github.com/bokeh/bokeh/blob/master/examples/howto/notebook_comms/Basic%20Usage.ipynb

https://github.com/bokeh/bokeh/blob/master/examples/howto/notebook_comms/Continuous%20Updating.ipynb

https://github.com/bokeh/bokeh/blob/master/examples/howto/notebook_comms/Jupyter%20Interactors.ipynb

关于Bokeh 动态改变 BoxAnnotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33402900/

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