散景动态更改BoxAnnotation [英] Bokeh dynamically changing BoxAnnotation

查看:89
本文介绍了散景动态更改BoxAnnotation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在IPython的interact函数中更新bokeh人物的渲染.我有看起来像的代码:

Is there possible to update bokeh figure's renderes in IPython's interact function. I have code which looks like:

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

推荐答案

从散景0.11开始,push_notebook函数现在可以更新任意的散景模型对象.因此,只需设置/更新框注释上的属性,然后调用push_notebook.您的代码如下所示:

As of Bokeh 0.11 the push_notebook function can now update arbitrary Bokeh model objects. So just set/update the properties on your box annotation and call push_notebook. Your code would look something like:

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笔记本:

You can see some howto notebooks here:

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

这篇关于散景动态更改BoxAnnotation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆