Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear Python/matplotlib memory? [duplicate]

Tags:

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.

like image 905
Tony Avatar asked Jul 02 '17 06:07

Tony


1 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...

like image 178
Adrian Avatar answered Oct 11 '22 13:10

Adrian