jupyter - 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)
解决方案
这个问题与我的设置无关,而只是因为我对散景缺乏了解。散景有状态。因此,如果您调用 output_file() 或者即使没有调用,它也会保存您的所有绘图,从而使它们也显示在新的浏览器选项卡中。解决方案是不这样做:)
将以下代码放在上面示例单元格的顶部解决了该问题:
bokeh.io.reset_output()
bokeh.io.output_notebook()
我在这里找到了答案。谢谢 bigreddot 和 martin-martin
从技术上讲,我的问题是重复的。然而,这并不明显,我会把它留在身边。
推荐阅读
- javascript - 无法建立连接 - 源不存在
- android - 当我运行我的旧 android 项目时,我从 build.gradle 收到一条错误消息
- php - 在 Laravel 中上传文件 - 路径错误
- networking - 计算机网络 - 位填充
- azure - 防止未经授权的流量 - Azure 静态网站
- javascript - 在移动设备上查看我的网站时出错,html 似乎不断收到 :before 问题
- c# - 如何使用 c# 在数据库优先方法中拥有审计列?
- ios - 避免在 URLComponents 中对主机进行百分比编码
- java - 无法在 Firestore 中按字符串查询。RuntimeException 字段“纬度”不是 java.lang.String
- arrays - 向量化环移数组