Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent plot from showing in jupyter notebook

How can I prevent a specific plot to be shown in Jupyter notebook? I have several plots in a notebook but I want a subset of them to be saved to a file and not shown on the notebook as this slows considerably.

A minimal working example for a Jupyter notebook is:

%matplotlib inline  from numpy.random import randn from matplotlib.pyplot import plot, figure a=randn(3) b=randn(3) for i in range(10):     fig=figure()     plot(b)     fname='s%03d.png'%i     fig.savefig(fname)     if(i%5==0):         figure()         plot(a) 

As you can see I have two types of plots, a and b. I want a's to be plotted and shown and I don't want the b plots to be shown, I just want them them to be saved in a file. Hopefully this will speed things a bit and won't pollute my notebook with figures I don't need to see.

Thank you for your time

like image 831
gota Avatar asked Sep 10 '13 11:09

gota


People also ask

How do I hide my output Jupyter?

There are two ways to hide content: To hide Markdown, use the {toggle} directive. To hide or remove code cells or their outputs, use notebook cell tags.

Is PLT show () blocking?

Answer #1: show() (not with block=False ) and, most importantly, plt. pause(. 001) (or whatever time you want). The pause is needed because the GUI events happen while the main code is sleeping, including drawing.


1 Answers

Perhaps just clear the axis, for example:

fig= plt.figure() plt.plot(range(10)) fig.savefig("save_file_name.pdf") plt.close() 

will not plot the output in inline mode. I can't work out if is really clearing the data though.

like image 155
Greg Avatar answered Sep 22 '22 03:09

Greg