所以我早些时候运行代码并收到以下警告:
Warning (from warnings module):
File "<string>", line 558
RuntimeWarning: More than 20 figures have been opened. Figures created through
the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly
closed and may consume too much memory. (To control this warning, see the rcParam
`figure.max_open_warning`).
Warning (from warnings module):
File "<string>", line 665
RuntimeWarning: More than 20 figures have been opened. Figures created through
the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly
closed and may consume too much memory. (To control this warning, see the rcParam
`figure.max_open_warning`).
我不会说谎,我很粗心,无论如何仍在运行它,而忽略了警告。 现在,每当我尝试运行脚本时,我的python shell都不会运行脚本。
因此,我试图从内存中删除图形,以允许我再次运行脚本。
我尝试了以下操作,但仍然无法运行代码:
plt.clf()
plt.cla()
f = plt.figure()
f.clear()
plt.close(f)
plt.close('all')
matplotlib.pyplot.figure().clear()
matplotlib.pyplot.close()
如何解决此问题?
答案 0 :(得分:0)
import matplotlib._pylab_helpers as pylhelp
pylhelp.Gcf().destroy_all()
尽管这可以满足您的需求,但它不是受支持的界面,并且可能已过时。我不知道这样做的其他方式,这是我推荐的唯一原因。