在 Jupyter notebook 中使用交互元素更新 Bokeh Span
Update a Bokeh Span with an interact element in Jupyter notebook
我正在尝试使用 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)
当我 运行 此代码时,我在 push_notebook()
处得到 ValueError: PATCH-DOC message requires at least one event
。我怀疑这表明未检测到对 cutoff.location
的更新,因此看起来好像没有要发送的更改。传递句柄似乎没有什么不同。查看 this github issue 中的示例代码,看起来 span 元素上曾经有一个 set
方法,但我的 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
这似乎是散景 0.12.11
的回归。您的代码适用于版本 0.12.10
,因此直接的解决方法是降级。我制作了 GitHub issue here,您可以关注。我们将尽快发布带有修复程序的新版本。
更新:该问题现已在最新版本的 Bokeh 中得到修复
我正在尝试使用 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)
当我 运行 此代码时,我在 push_notebook()
处得到 ValueError: PATCH-DOC message requires at least one event
。我怀疑这表明未检测到对 cutoff.location
的更新,因此看起来好像没有要发送的更改。传递句柄似乎没有什么不同。查看 this github issue 中的示例代码,看起来 span 元素上曾经有一个 set
方法,但我的 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
这似乎是散景 0.12.11
的回归。您的代码适用于版本 0.12.10
,因此直接的解决方法是降级。我制作了 GitHub issue here,您可以关注。我们将尽快发布带有修复程序的新版本。
更新:该问题现已在最新版本的 Bokeh 中得到修复