Reputation: 91
I need to create lots of figures, then use savefig
to save the figure.
But after about 280 pictures, it throws the exception RuntimeError: Could not allocate memory for image
Is there some function like clear()
in Matplotlib ?
Upvotes: 6
Views: 17455
Reputation: 157
Yes, you can use:
clf()
: in order to clean the current figure close()
: in order to close the current windowUpvotes: 7
Reputation: 36
You can try:
i=1
while i<=280:
plt.figure(i).clear()
i+=1
But you have to numbered your figures:
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()
Upvotes: 0