Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Improve docs regarding plt.close().#29839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
lib/matplotlib/pyplot.py Outdated
pyplot maintains a reference to figures created with `figure()` until | ||
`close()` is called on them. Closing figures is thus necessary to prevent | ||
running out of memory (see also :rc:`figure.max_open_warning`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can we get this more in the direction thatclose()
is the explicit way to deregister a figure from pyplot? I want to prevent the implication that every figure() must be paired with close(). Closing a figure window that was created using show() also deregisters the figure from pyplot and hence close() is not needed in that usage scenario.
Something like
pyplot maintains a reference to figures created with
figure()
. When work on the figure is completed, it should be closed, i.e. deregistered from pyplot, to free its memory (see also :rc:figure.max_open_warning
).
Closing a figure window created byshow()
automatically deregisters the figure. For all other use cases, most prominentlysavefig()
withoutshow()
, the figure must be deregistered explicitly usingclose()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
sure, done
timhoffm commentedApr 1, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Do we have an explicit documentation on the lifecycle of figures with pyplot (I'm not aware of that). If so, we could link there. If not, that's for another time/PR. Anybody can merge after CI has run. |
90385b4
intomatplotlib:mainUh oh!
There was an error while loading.Please reload this page.
…839-on-v3.10.xBackport PR#29839 on branch v3.10.x (Improve docs regarding plt.close().)
See#29782 (comment)
PR summary
PR checklist