防止情节在 jupyter notebook 中显示 [英] prevent plot from showing in jupyter notebook

查看:47
本文介绍了防止情节在 jupyter notebook 中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何防止在 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.

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 notebook 中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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