如何阻止bokeh在Jupyter Notebook中打开新标签页? [英] How to stop bokeh from opening a new tab in Jupyter Notebook?

查看:342
本文介绍了如何阻止bokeh在Jupyter Notebook中打开新标签页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,在将其标记为重复之前,我已经阅读了其他解决方案,但是不幸的是,没有一个对我有用.

First of all, before this is tagged as duplicate, I have read the other solutions and unfortunately none of them worked for me.

我的问题是我想在Juypter Notebook(仅在Jupyter Notebook)中显示散景图,而不是在新的标签/窗口中显示.

My problem is that I want to display a bokeh plot in Juypter Notebook (and only in Jupyter Notebook), not in a new tab/window.

在官方文档中此处被告知我只需要更改

In the official documentation here I am told that I only need to change

output_file

output_notebook

即使我这样做,即使情节现在已显示为行内,bokeh也不会停止,也将打开一个新选项卡并在其中不必要地显示情节.

Even though the plot is now displayed inline if I do that, bokeh won't stop also opening a new tab and needlessly displaying the plot there.

由于我要在项目中创建很多绘图,因此很高兴不必总是关闭此新选项卡并返回到笔记本,而是让它停止创建新选项卡,就像它能正常工作一样与例如matplotlib.

Since I'm gonna create lots of plots in my project, it'd be very nice to not always have to close this new tab and return to notebook, but just have it stop creating new tabs, just as it would work with e.g. matplotlib.

让我感到困惑的是,如果我加载

What confuses me is that if I load up the official tutorial and enter code there, for example

import numpy as np

x = np.linspace(0, 10, 100)
y = np.exp(x)

p = figure()
p.line(x, y)

show(p)

没有打开新的选项卡.如果现在我在计算机的Juypter Notebook上本地运行相同的代码,它会确实打开一个新标签页.

there is no new tab opened. If I now run the same code locally on my machine's Juypter Notebook, it does open up a new tab.

我已经尝试了一段时间以解决此问题,我们将不胜感激.

I've been trying for a while now to fix this, any help would be very much appreciated.

在此先感谢Vincent

Thanks in advance, Vincent

推荐答案

您需要在笔记本顶部调用output_notebook,但仅 调用output_notebook.如果完全调用output_file,则将激活一种持久模式,该模式将输出保存到文件中,并使show打开带有这些文件的新选项卡.您将需要调用reset_output清除该持久模式.

You need to call output_notebook at the top of your notebook, but only call output_notebook. If you call output_file at all, that activates a persistent mode that saves output to files, and causes show to open new tabs with those files. You would need to call reset_output to clear that persistent mode.

为方便起见,由于有几个用户要求使用它,所以如果提供了 no 输出模式,则show的行为就像默认调用了output_file一样.无法从Binder教程中打开选项卡的原因是,从技术上讲,在Binder服务器上远程运行的代码无法在本地浏览器上打开选项卡(这是一件好事).

As a convenience, since several users asked for it, if no output mode is supplied, show behaves as though output_file was called as a default. The reason a tab is not opened from the Binder tutorial is because it is not technically possible for code running remotely on Binder server to open a tab on your local browser (which is a very good thing).

这篇关于如何阻止bokeh在Jupyter Notebook中打开新标签页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆