You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
figure created using figure.Figure doesn't save figure #12447
Eh, that won't be easy. And still won't be very useful in the end.
Can I ask why you are instantiating the Figure object directly? Usually,
the only time one does that is when embedding in a GUI widget and in those
situations, you don't instantiate the baseclass, you instantiate the
GUI-specific Figure class.
I'm creating several images in loop and the memory keeps increasing and one solution given in so was to create figure from figure.Figure instead of plt.figure
Eh, that won't be easy. And still won't be very useful in the end. Can I ask why you are instantiating the Figure object directly? Usually, the only time one does that is when embedding in a GUI widget and in those situations, you don't instantiate the baseclass, you instantiate the GUI-specific Figure class. …
On Mon, Oct 8, 2018 at 2:11 PM Antony Lee @.***> wrote: (I think we should perhaps attach a FigureCanvasBase by default to Figures...). — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#12447 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AARy-MKi-Z1TE5cOuhZkMm0OMyV2AKhFks5ui5VFgaJpZM4XNagC .
Ah, yeah, that isn't a great solution. The better way is to simply recycle
the figure object. So, something like this:
```
fig = plt.figure()
for i in range(5):
axs = fig.subplots(5, 1)
# Do your plotting
fig.savefig(...)
fig.clear()
```
The memory usage grows because when the old figures are closed out, they
don't actually go away completely. This happens for any pyplot-managed
figures. I even have a PR adding documentation describing this exact
situation.
On Mon, Oct 8, 2018 at 2:57 PM Abbas ***@***.***> wrote:
I'm creating several images in loop and the memory keeps increasing and
one solution given in so <https://stackoverflow.com/a/12300012/1437877>
was to create figure from figure.Figure instead of plt.figure
Eh, that won't be easy. And still won't be very useful in the end. Can I
ask why you are instantiating the Figure object directly? Usually, the only
time one does that is when embedding in a GUI widget and in those
situations, you don't instantiate the baseclass, you instantiate the
GUI-specific Figure class.
… <#m_-4227168573890813519_>
On Mon, Oct 8, 2018 at 2:11 PM Antony Lee ***@***.***> wrote: (I think we
should perhaps attach a FigureCanvasBase by default to Figures...). — You
are receiving this because you are subscribed to this thread. Reply to this
email directly, view it on GitHub <#12447 (comment)
<#12447 (comment)>>,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AARy-MKi-Z1TE5cOuhZkMm0OMyV2AKhFks5ui5VFgaJpZM4XNagC
.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#12447 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-NJQxer4eKJ3WGtlaY0fwNoeKdR8ks5ui6ATgaJpZM4XNagC>
.
The problem is that the figure stays behind in the pyplot module. This is
actually by design and it is how the pyplot interface works. Now, we should
double-check the behavior when fig.close() is called, as I suspect that
could be tightened up, but the slightly confusing part is that leaving the
scope of a for-loop, for example, would not garbage-collect the figure. So,
you are left with either recycling the figure, or explicitly closing it.
There isn't actually a fig.close() method... (that makes sense as "closing" is a pyplot concept, not a figure concept)
There's plt.close(fig) and that does the right thing.
Activity
anntzer commentedon Oct 8, 2018
(I think we should perhaps attach a FigureCanvasBase by default to Figures...).
WeatherGod commentedon Oct 8, 2018
anntzer commentedon Oct 8, 2018
Why? It's literally
self.canvas = FigureCanvasBase()instead ofself.canvas = None...Well, then you'd get to save these figures...
abbazs commentedon Oct 8, 2018
I'm creating several images in loop and the memory keeps increasing and one solution given in so was to create figure from
figure.Figureinstead ofplt.figureWeatherGod commentedon Oct 8, 2018
jklymak commentedon Oct 9, 2018
What sticks around after
figure.close? We should plug that shouldn't we?WeatherGod commentedon Oct 9, 2018
anntzer commentedon Oct 9, 2018
There isn't actually a fig.close() method... (that makes sense as "closing" is a pyplot concept, not a figure concept)
There's plt.close(fig) and that does the right thing.
jklymak commentedon Oct 9, 2018
Indeed. But OTOH:
shouldn't keep growing memory use ad-infinitum, should it?
anntzer commentedon Oct 9, 2018
That's almost certainly #9141 (this only appears to leak when using qt, not with other interactive or noninteractive backends).
jklymak commentedon Oct 9, 2018
OK, agreed - with Agg memory use grows a tiny bit, but very very slowly.
rudrathegreat commentedon Nov 8, 2018
Another way I found which works (requirements below) -
And then, if you can, be able to save this to your folder -
And possibly even save it using
scipy.io.wavfile.write-Requirements
I hope that helped!
anntzer commentedon Jan 14, 2020
Closed by #12450 (AFAICT).