我需要创建大量数据,然后使用savefig
来保存数字。
但是在大约280张图片之后,它会抛出异常RuntimeError: Could not allocate memory for image
在Matplotlib中是否有类似clear()
的功能?
答案 0 :(得分:3)
是的,您可以使用:
clf()
:为了clean the current figure close()
:为了close the current window 答案 1 :(得分:0)
您可以尝试:
i=1
while i<=280:
plt.figure(i).clear()
i+=1
但是你必须对你的数字进行编号:
import matplotlib.pyplot as plt
from numpy import *
# example of data:
x = linspace(0,4,1e3)
data = sin(10*x)
plt.figure(1)
plt.plot(x, data)
plt.show()