thanks for your effort; I had tried the approach of clearing & replacing the plot myself, too. Unfortunately, that approach has a different problem: Because of the figure's size, I have to present it with scrollbars, and clearing & reusing the plot does not seem to work when resizing & scrolling the plot. I had posted that problem as a question at Stackoverflow (as http://stackoverflow.com/questions/13197469 ), since I hoped it might be "easier"; i.e., just a misunderstanding on my part of how to wire together the scrollbars/canvas/figure. Please note that, while I also use plt.figure(...) in the post at Stackoverflow, the effect remains the same when using Figure(...) and ax.plot(...).
So basically I'm stuck between a rock and a hard place - I can either have the memory issue reported previously; or the plot won't behave properly with scrolling+resizing.
I am wondering: Should repeatedly creating Figures in a Tkinter GUI work, and could this be a Matplotlib bug worth mentioning on some bug tracker?
Thanks & Regards
On Fri, 02 Nov 2012 16:45:22 +0100, <email@example.com> wrote:
Date: Fri, 2 Nov 2012 12:01:35 +0100
From: Vlastimil Brom <vlastimil.brom@...287...>
Subject: Re: [Matplotlib-users] Figures piling up in Tkinter GUI
Content-Type: text/plain; charset=ISO-8859-1
2012/11/1 Hans Bering <hans.bering@...2007...>:
I'm building a small Tkinter GUI using matplotlib, in which I have to
change/update plots quite often depending on user input (with different
contents & sizes, in different places in the GUI, etc.; but always only
one figure at a time).
As a first resort, I regenerated the figures with plt.figure(...) whenever necessary; unfortunately, the program happily accumulated memory with
every new figure until the computer would no longer cooperate in a timely fashion. The following minimal script should demonstrate the tendency:
I'd recommend to use an embedded plot and only clear and replace its
I only roughly adapted that source to use your function and the memory
usage appears to be more effective (although there is some increase
too - as displayed in Process Explorer). Would some variation of the
following work for you?