Improve docs regarding plt.close().#29839
Conversation
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.
Can we get this more in the direction that close() 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().
|
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. |
…839-on-v3.10.x Backport PR #29839 on branch v3.10.x (Improve docs regarding plt.close().)
See #29782 (comment)
PR summary
PR checklist