Boketh plot hide html site and show output only in Jupyter? - python

With the bokeh package, I created a graph visualization and with show(plot) the output is shown in Jupyter but also at the same time a new tab in the browser is opened with the output. I only want to plot it in a Jupyter cell without opening the plot as a new html file. Is this somehow possible?
#Booketh plot
output_file("thisisaplot.html")
show(plot)

According to the documentation, you should be able to do that by calling output_notebook() before calling show().
Note: As pointed out by #bigreddot, if you were using output_file in the kernel, changing to output_notebook may not take place right away. You will need to either call reset_output(), or restart your kernel for the change to take place.

Related

How to save an interactive plot?

I'm creating an interactive plot using Pywedge Bibliothek in jupyter notebook using this code
x=pw.Pywedge_Charts(df, c=None, y='Number_Trips')
charts=x.make_charts()
charts
an example of the output is as follows
and i can desactivate as well as activate the day i want to see.. my question is how can i save it and keep it interactive to use it in a website or if it is even possible?
The way to save interactivity is to save the source of df and the code to generate the plot. To open an interactive plot, run the script that generates it.

Automatically cleaning the plot pane in Python Spyder

I would like to delete all the plots in the plot pane with some code so I can automatically "clear" the interface. I am aware there is a button you can click that deletes them all. However, I would like to avoid having to click manually on the plot pane to delete all the plots generated in the previous runs.
Right now I am already clearing the console and the variable explorer by using (which I got from link):
try:
from IPython import get_ipython
get_ipython().magic('clear')
get_ipython().magic('reset -f')
except:
pass
Now I would like to add there something that also clears the plot pane.
(Spyder maintainer here) It is not possible to remove all plots from the Plots pane using code, sorry.

Can I set matplotlib savefig() options for a whole notebook?

I am working in a jupyter notebook that produces several figures, each of which gets saved to an svg file.
In each call to savefig() I am using bbox_inches='tight' as such:
ax.figure.savefig(path.join(graphics_dir,'filename1.svg'),bbox_inches='tight')
ax.figure.savefig(path.join(graphics_dir,'filename2.svg'),bbox_inches='tight')
...
Is there some configuration setting I can use to set bbox_inches='tight' for the whole notebook so I don't have to pass it in every time?
Thanks!
The rcParameter
savefig.bbox : tight
This can be set in the matplotlib rc file, or via code on top of your notebook, like
plt.rcParams["savefig.bbox"] = "tight"

Spyder: refresh existing plot window instead of opening a new one

I want to show plots in a separate window. Currently I have the IPython graphics backend set to "automatic".
When I re-run the code (or plot another figure), Spyder opens a new plot window. Is it possible to refresh the figure in the window that is already opened instead of opening a new one?
The GUI window that opens when you call plt.show() is bound to a figure. You cannot change the figure inside it. (Well, to be precise, there might be an option of obtaining a handle from the operating system and manipulating its content, but I assume this is not worth the effort.)
Re-running the code actually means that you produce a new figure since the code does not know that it's been run before.
So, exchanging the figure or reusing the window to plot a different figure is not possible.
What is possible however is to use the figure and manipulate the figure while it's open. This is done via plt.ion(). After calling this command in IPython you can adapt the figure, e.g. adding new lines to it etc.
See this example:
At IN [6] the window opens and when IN [7] is executed, the figure stays open and the content changes.
Sure, it is possible with Spyder while in the same running kernel. Try the following example using num as parameter to plt.figure(), where num will always refer to the same figure and refresh it if already opened. Also works with plt.subplots().
import matplotlib.pyplot as plt
from scipy import *
t = linspace(0, 0.1,1000)
w = rand(1)*60*2*pi
fig = plt.figure(num=10, clear=True, figsize = [10,8])
plt.plot(t,cos(w*t))
plt.plot(t,cos(w*t-2*pi/3))
plt.plot(t,cos(w*t-4*pi/3))

Bokeh: Using CustomJS opens new window

I'd like to leverage Bokeh's rich and excellent library to create plots that allows a user to select groups for plotting data within Jupyter Notebook.
I have followed the following tutorial:
http://docs.bokeh.org/en/latest/docs/gallery/slider.html
However, when combining this tutorial with the "output_notebook" module, the plots are handled both within the notebook and in a new window. I have isolated the problem to the CustomJS module, probably the callback method.
How do I toggle off plotting in a new window?
I have followed the tutorial and made the following changes:
from bokeh.io import output_notebook
output_notebook()
and in show:
show(layout, notebook_handle=True)
(Writing as an answer so the information is more prominent)
The output_file command initiates a persistent operational mode. All subsequent show commands will result in the specified file being created (or overwritten). Merely deleting a notebook cell with output_file will not turn this mode off. You must either:
explicitly call reset_output to cancel, or
restart the notebook kernel

Categories