3
我有一個Bokeh圖,我在LabelSet和BoxAnnotation的形式中添加一些數據作爲疊加,但我希望能夠動態啓用/禁用此疊加。在散景中隱藏註釋
我可以啓用/隱藏劇情already中的一些行,但註釋系統似乎不同。我走到這一步,已經
正開始
from ipywidgets import interact
from bokeh.plotting import figure as bf
from bokeh.layouts import layout as bl
from bokeh.models import Toggle, BoxAnnotation, CustomJS
from bokeh.io import push_notebook, show, output_notebook
output_notebook()
控件生成
p = bf(title='test', x_range=(0,1), y_range=(0,1))
x = [1/3, 2/3]
y=[1/3, 2/3]
p.circle(x=x, y=y, size=15)
box = BoxAnnotation(left=None, right=0.5, fill_color='red', fill_alpha=0.1)
p.add_layout(box)
交互
code = '''\
if toggle.active
box.visible = true
console.log 'enabling box'
else
box.visible = false
console.log 'disabling box'
'''
callback = CustomJS.from_coffeescript(code=code, args={})
toggle = Toggle(label="Red Box", button_type="success", callback=callback)
callback.args = {'toggle': toggle, 'box': box}
layout = bl([p], [toggle])
show(layout)
當我檢查了JS控制檯中,如果/ else子句被觸發正如預期的那樣,Toggle
的作品,但紅色框保持原位,無論是在Firefox中,如IE