matplotlib在制作许多情节时崩溃

时间:2017-04-18 15:07:59

标签: python matplotlib jupyter-notebook

我有一个循环用matplotlib(jupyter notebook)制作~90个图(png)。当循环遍历每个图时,在图37周围,python崩溃(内核死亡)。起初我以为是因为我没有正确清理数字,但这似乎不是问题...这是我的代码的删节版本:

%pylab inline
import numpy as np
from scipy import integrate
from scipy import interpolate
from scipy import stats
import pandas as pd
import psycopg2
from scipy.interpolate import UnivariateSpline
from scipy.signal import savgol_filter
from joblib import Parallel, delayed
import gc


for p in plots_agm:
    cnt=cnt+1
    print(cnt)
    fig, ax = plt.subplots(3, 2, figsize=(8.5,11),sharex=True,sharey=True)
    ax = ax.flatten()
    for i,d in enumerate(dat.keys()):


   ######### A BUNCH OF CALCULATIONS AND PLOTTING FOR EACH FIGURE ###########

    fig.savefig('+p.replace(' ','_')+'_v3.png')
    #pp.savefig(fig)
    plt.clf()
    plt.close(fig)
    #plt.cla()
    #plt.close()
    #plt.clf()
    #plt.cla()
    #fig.clf()
    #pylab.close(fig)
    #plt.close(fig)
    #plt.close('all')
    #del(fig)
    #del(ax)
    gc.collect()

我尝试了很多方法来清除图形(正如您在代码中注释掉的部分中所看到的那样)。

在运行jupyter笔记本的终端中,所有内容都是:

警告:root:内核9a4a2b77-0b43-4700-a30f-2c7743463c30重启

0 个答案:

没有答案