cxlove
cxlove

Reputation: 91

How to clear the cache in Matplotlib for python

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

Answers (2)

g-abello
g-abello

Reputation: 157

Yes, you can use:

Upvotes: 7

Renaud Pfeiffer
Renaud Pfeiffer

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

Related Questions