我正在尝试使用 jupyter 小部件在散景中制作一个跨度。
from ipywidgets import interact
import numpy as np
from scipy.stats import norm
from bokeh.sampledata.daylight import daylight_warsaw_2013
from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import figure
from bokeh.models import Span
output_notebook()
p = figure()
x_axis = np.arange(-10, 10, 0.001)
# Mean = 0, SD = 2.
y_axis = norm.pdf(x_axis,0,2)
p.line(x_axis, y_axis, line_dash='solid', line_width=2)
cutoff = Span(location=1,
dimension='height', line_color='green',
line_dash='dashed', line_width=2)
p.add_layout(cutoff)
show(p, notebook_handle=True)
def update(new_cutoff_location):
cutoff.location = new_cutoff_location
push_notebook()
interact(update, new_cutoff_location = 1.0)
当我运行这段代码时我得到ValueError: PATCH-DOC message requires at least one event
at push_notebook()
。我怀疑这表明更新cutoff.location
没有被检测到,因此看起来好像没有要发送的更改。传递手柄似乎没有什么区别。查看示例代码这个 github 问题 https://github.com/bokeh/bokeh/issues/3993,看起来曾经有一个set
span 元素上的方法,但我的 span 元素上似乎没有cutoff
。也许我应该调用一个不同的函数来注册更改?
我在 bokeh 0.12.11 上使用 jupyter 1.0.0、jupyter-client 5.1.0、jupyter-console 5.2.0、jupyter-core 4.4.0