Python Forum

Full Version: How to clear matplotlib graphs from memory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I was running code earlier and got the following warning:

Warning (from warnings module): File "", line 558 RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (matplotlib.pyplot.figure) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam figure.max_open_warning).

Warning (from warnings module): File "", line 665 RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (matplotlib.pyplot.figure) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam figure.max_open_warning).

Not going to lie, I was being very careless and was still running it anyway, ignoring the warning. Now whenever I try to run the script, my python shell doesn't run the script.

So I am trying to remove the graphs from the memory to allow me to run script again.

I have tried the following and it still won't let me run the code:

1) plt.clf()
2) plt.cla()
3) f = plt.figure()
f.clear()
plt.close(f)

4) plt.close('all')

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

How can I fix this issue?

Thanks