【问题标题】:jupyterlab: bokeh plot displays in wrong browserjupyterlab:散景图显示在错误的浏览器中
【发布时间】:2019-02-14 18:55:34
【问题描述】:

我有一个运行 jupyterlab 的 VM,并已将其打开以供外部访问。当 jupyter-lab 启动时,会打开一个本地浏览器,这很好。

在外部,我访问了 jupyterlab,一切似乎都可以正常工作。但是,当我绘图时,输出不会显示在浏览器中,而是显示为 本地浏览器中的一个新选项卡,该浏览器以 jupyter-lab 启动。

如果我有%matplotlib inline,也会发生同样的事情。

以下内容要好一些,因为现在内容是内联显示的。但是,other 浏览器中仍会打开一个新选项卡。

%matplotlib inline
from bokeh.plotting import figure, show, output_notebook
from bokeh.sampledata.iris import flowers

output_notebook()

colormap = {'setosa': 'red', 'versicolor': 'green', 'virginica': 'blue'}
colors = [colormap[x] for x in flowers['species']]

p = figure(title = "Iris Morphology")
p.xaxis.axis_label = 'Petal Length'
p.yaxis.axis_label = 'Petal Width'

p.circle(flowers["petal_length"], flowers["petal_width"],
        color=colors, fill_alpha=0.2, size=10)

# output_file("iris.html", title="iris.py example")

show(p)

【问题讨论】:

    标签: jupyter jupyter-lab


    【解决方案1】:

    问题与我的设置无关,而只是因为我对散景缺乏了解。散景有状态。因此,如果您调用 output_file() 或者即使没有调用,它也会保存您的所有绘图,从而使它们也显示在新的浏览器选项卡中。解决方案是不要这样做:)

    将以下代码放在上面示例单元格的顶部解决了这个问题:

    bokeh.io.reset_output()
    bokeh.io.output_notebook()
    

    我找到了答案here。谢谢 bigreddot 和 martin-martin

    从技术上讲,我的问题是重复的。然而,它不够明显,我会留下它。

    【讨论】:

      猜你喜欢
      • 2022-07-13
      • 2013-01-02
      • 1970-01-01
      • 2013-03-11
      • 1970-01-01
      • 2017-03-27
      • 1970-01-01
      • 2014-05-08
      • 2021-06-13
      相关资源
      最近更新 更多