首页 > 解决方案 > jupyterlab:散景图显示在错误的浏览器中

问题描述

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

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

如果我有同样的事情%matplotlib inline

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

%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)

标签: jupyterjupyter-lab

解决方案


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

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

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

我在这里找到了答案。谢谢 bigreddot 和 martin-martin

从技术上讲,我的问题是重复的。然而,这并不明显,我会把它留在身边。


推荐阅读