防止剧情显示在jupyter笔记本中 [英] prevent plot from showing in jupyter notebook
问题描述
如何防止特定情节显示在Jupyter笔记本中?我在笔记本中有几个图,但是我希望将其中的一部分保存到文件中,而不要在笔记本上显示,因为这样会大大降低速度.
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.
Jupyter笔记本的最小工作示例是:
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)
如您所见,我有两种类型的绘图,a和b.我想绘制a并显示,而我不想b示,我只希望将它们保存在文件中.希望这会加快速度,并且不会用我不需要看到的数字污染笔记本.
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.
谢谢您的时间
推荐答案
也许只是清除轴,例如:
Perhaps just clear the axis, for example:
fig= plt.figure()
plt.plot(range(10))
fig.savefig("save_file_name.pdf")
plt.close()
不会在inline
模式下绘制输出.我无法确定是否确实要清除数据.
will not plot the output in inline
mode. I can't work out if is really clearing the data though.
这篇关于防止剧情显示在jupyter笔记本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!