How to clear Python/matplotlib memory?

Viewed 5425

Python puts out a memory error after drawing a few graphs with pyplot (I draw plots with over a million points on a laptop - and how many graphs can be drawn before the error has direct relationship with the amount of points).

How can the memory be cleared after, so that I can draw more graphs? The only option now is to ctrl + . to restart the kernel.

I have tried the recommended:

matplotlib.pyplot.close("all")
matplotlib.pyplot.clf()

Doesn't clear the errors.

3 Answers

I've been battling this for weeks and the only thing that worked for me was the solution presented here:

How to clear memory completely of all Matplotlib plots

matplotlib.pyplot.figure().clear()
matplotlib.pyplot.close()

The following:

plt.cla()

and

plt.clf() 

didn't work for me at all... I suspect because it was designed for when you have more than one subplot...

Related