我生成了一個腳本,我不顯示,但存儲硬盤驅動器的很多數字。過了一會兒,我得到的消息蟒蛇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