我生成了一个脚本,我不显示,但存储硬盘驱动器的很多数字。过了一会儿,我得到的消息蟒蛇plt:关闭或清除图不起作用
/usr/lib/pymodules/python2.7/matplotlib/pyplot.py:412:RuntimeWarning:超过20倍的数字已被打开。通过pyplot接口创建的数字(
matplotlib.pyplot.figure
)会一直保留,直到显式关闭并可能消耗太多内存。 (要控制此警告,请参阅rcParamfigure.max_num_figures
)。 max_open_warning,RuntimeWarning)
因此,我试图关闭或清除存储后的数字。到目前为止,我尝试了以下所有方面,但没有人能够工作。我仍然从上面得到消息。
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正确的方法TTK :: ThemeChanged “
为了确保您总是工作在同一个图上,只是使用这个'plt.figure(1).clf()' – Julien
plt.close(fig)should do it – Y0da
@Julien这也会产生RuntimeWarning – AnnetteC