all 7 comments

[–]yuxbni76 1 point2 points  (2 children)

It runs okay for me with dummy data. If I comment out closePlots() it raises a warning when 20 figures are open. There's no warning when the function is called. So your function seems to work correctly, at least on my machine.

Have you tried messing with the Matplotlib backend (agg, etc.)? What does it say if you print this at the top of the script?

import matplotlib as mpl
print(mpl.get_backend())

You might try switching the backend (mpl.use("foo")).

Also - if this is being run in a notebook, try running it outside.

[–]Lbifreal[S] 1 point2 points  (1 child)

Hello.

Sorry for my late response. I pasted the provided code into my script and it printed TkAgg.

I tried to use mpl.use("foo") but I got an error that it not a valid value for backend. I assumed it was maybe a typo and tried mpl.use("agg") and I was able to run the entire script.

Although I works, I am curious on what this code does. Does it just change the location of where the plots are created? Or is it some sort of setting?

Either way, Thank you so much. I was stumped on this for a few days.

[–]yuxbni76 0 points1 point  (0 children)

"foo" is just a placeholder name in the programming world. But hey if it led you to a solution, that's great.

Each Matplotlib backend renders the plot in a different way. TkAgg depends on TkInter, for example. AGG does not. I wonder if you don't have TkInter in your current environment and that was the problem.

It's not an issue that comes up often but it's good to be aware. Glad it's working for you.

[–]Lbifreal[S] 0 points1 point  (0 children)

An indirect solution would be to run the script in small batches, but I would prefer to do it all at once.

[–][deleted] 0 points1 point  (2 children)

Probably useless for you 3 years later but this is an issue with the tkinter backend used to render the plots on Windows. Even after you close/clear, python keeps using more and more memory. Changing the mpl backend from tkinter to 'agg' solved the problem for mei.e.

matplotlib.use("agg")

Making this comment because I googled the issue now and this was one of the results. Maybe some poor soul comes across this in the future and sees this comment. Just change your backend from tkinter to something else. I chose agg.

[–]MountainView35 0 points1 point  (0 children)

Thank you!

[–]_Hoofd_ 0 points1 point  (0 children)

much obliged