gpt4 book ai didi

python-2.7 - 无法在 IPython 中内联 Bokeh

转载 作者:行者123 更新时间:2023-12-02 01:40:31 32 4
gpt4 key购买 nike

我安装了最新的 Bokeh 和 IPython,我尝试运行以下命令:(所有这些导入在后面的代码中都是相关的)

import pandas as pd
import datetime
import matplotlib.pyplot as plt
import itertools as itt
import bokeh.plotting as bk
bk.output_notebook()

xs = [0,1,2,3,4,5]
ys = [x**2 for x in xs]

p.line(xs, ys, line_width=2)
p.circle(xs,ys)
bk.show(p)

运行这 2 个单元后,我得到:

Javascript error adding output! ReferenceError: Bokeh is not defined See your browser Javascript console for more details.

因此,我运行控制台并看到:

ReferenceError: Bokeh is not defined Stack trace: @http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302 line 4 > eval:1:1 .globalEval@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:4231 .domManip@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:5:21389 .append@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:5:18980 OutputArea.prototype._safe_append@http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:414:13 OutputArea.prototype.append_display_data@http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:534:13 OutputArea.prototype.append_output@http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:320:13 OutputArea.prototype.handle_output@http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:234:9 CodeCell.prototype.get_callbacks/<.iopub.output@http://localhost:8888/static/notebook/js/codecell.js?v=20150304125302:456:21 Kernel.prototype._handle_output_message@http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:997:13 .proxy/i@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:5486 Kernel.prototype._handle_iopub_message@http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:1024:13 Kernel.prototype._finish_ws_message@http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:866:17 .proxy/i@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:5486 deserialize@http://localhost:8888/static/services/kernels/serialize.js?v=20150304125302:60:13 Kernel.prototype._handle_ws_message@http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:857:9 .proxy/i@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:5486 outputarea.js:416

在看到这个之前,bk.show(p) 显示了一个扭曲的图,说“Hello Word”,但是所有的按钮都变形了。matplotlib 工作正常。

最佳答案

此问题已在 https://github.com/bokeh/bokeh/issues/2024 中解决它将加载 BokehJS 的代码移动到 output_notebook 而不是在导入 bokeh 时尝试这样做。但是,我仍然建议将 bk.output_notebook 放在它自己的 ipython 单元格中,别无其他。我将更新文档以尽快反射(reflect)这一建议。问题在于 Bokeh 使用 IPython 的“发布”机制来加载自身,如果您将其他东西放在也有输出的单元格中,它可能会干扰它。这就是 IPython notebook 的工作方式,除了建议将 output_notebook 放在它自己的位置之外,别无他法,因此它的输出保证是正确的。

关于python-2.7 - 无法在 IPython 中内联 Bokeh ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28854515/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com