How to stop bokeh from opening a new tab in Jupyter Notebook?

做~自己de王妃 提交于 2019-12-06 18:50:15

问题


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

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

to

output_notebook

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.

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)

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.

Thanks in advance, Vincent


回答1:


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.

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




回答2:


Adding an explicit example to @bigreddot's answer:

You might have ran bokeh.io.output_file() somewhere in your notebook, to save noteable graphs. However, now you only want to experiment with some plots quickly to inspect the data.

Simply reset your settings to stop saving to file in any cell in your notebook like so:

import bokeh.io
# this is here only for completeness to clarify where
# the methods are nested (you probably already imported this earlier)


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

You can activate saving to file again later to keep the interesting graphs.



来源:https://stackoverflow.com/questions/51512907/how-to-stop-bokeh-from-opening-a-new-tab-in-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!