我试图使用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
获得push_notebook()
。我怀疑这表明没有检测到对cutoff.location
的更新,所以它看起来好像没有要发送的更改。通过手柄似乎没有什么区别。看看this github issue中的示例代码,看起来在span元素上曾经有一个set
方法,但在我的span元素cutoff
上似乎没有。也许我应该调用一个不同的函数来注册更改?
我在散景0.12.11上使用jupyter 1.0.0,jupyter-client 5.1.0,jupyter-console 5.2.0,jupyter-core 4.4.0
这似乎是Bokeh 0.12.11
的回归。您的代码适用于版本0.12.10
,因此立即解决方法是降级。我已经制作了你可以效仿的GitHub issue here。我们将尽快发布一个新的点发布版本。
更新:此问题现已在最新版本的Bokeh中修复