使用 Jupyter Notebook 中的交互元素更新 Bokeh Span

2024-01-22

我正在尝试使用 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,看起来曾经有一个setspan 元素上的方法,但我的 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


这似乎是 Bokeh 中的回归0.12.11。您的代码适用于版本0.12.10因此,立即的解决方法是降级。我做了GitHub 问题在这里 https://github.com/bokeh/bokeh/issues/7268您可以遵循。我们将尽快发布包含修复程序的新版本。

更新:该问题现已在最新版本的 Bokeh 中修复

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Jupyter Notebook 中的交互元素更新 Bokeh Span 的相关文章

随机推荐