如何清除Matplotlib中用于python的缓存

时间:2014-11-17 06:50:49

标签: python matplotlib

我需要创建大量数据,然后使用savefig来保存数字。

但是在大​​约280张图片之后,它会抛出异常RuntimeError: Could not allocate memory for image

在Matplotlib中是否有类似clear()的功能?

2 个答案:

答案 0 :(得分:3)

是的,您可以使用:

答案 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()