我用脚本生成了大量图形,我不显示这些图形而是将其存储到硬盘驱动器。过了一会儿我收到消息
/usr/lib/pymodules/python2.7/matplotlib/pyplot.py:412: RuntimeWarning: 已打开超过 20 个数字。通过 pyplot 接口创建的图形(matplotlib.pyplot.figure
)会保留到显式关闭为止,并且可能会消耗太多内存。 (要控制此警告,请参阅 rcParamfigure.max_num_figures
)。
max_open_warning、运行时警告)
因此,我尝试在存储后关闭或清除数字。到目前为止,我尝试了以下所有方法,但没有一个有效。我仍然收到上面的消息。
plt.figure().clf()
plt.figure().clear()
plt.clf()
plt.close()
plt.close('all')
plt.close(plt.figure())
此外,我尝试通过以下方式限制开放数字的数量
plt.rcParams.update({'figure.max_num_figures':1})
下面是一段示例代码,其行为与上述类似。我在尝试过的地方添加了我尝试过的不同选项作为评论。
from pandas import DataFrame
from numpy import random
df = DataFrame(random.randint(0,10,40))
import matplotlib.pyplot as plt
plt.ioff()
#plt.rcParams.update({'figure.max_num_figures':1})
for i in range(0,30):
fig, ax = plt.subplots()
ax.hist([df])
plt.savefig("/home/userXYZ/Development/pic_test.png")
#plt.figure().clf()
#plt.figure().clear()
#plt.clf()
#plt.close() # results in an error
#plt.close('all') # also error
#plt.close(plt.figure()) # also error
完整地说,这是我使用时遇到的错误plt.close
:
无法调用“事件”命令:应用程序已被破坏
执行“事件生成$w ”时
(过程“ttk::ThemeChanged”第 6 行)
从“ttk::ThemeChanged”中调用