GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Improve docs regarding plt.close(). by anntzer · Pull Request #29839 · matplotlib/matplotlib

Conversation

@anntzer

@anntzer anntzer commented Mar 31, 2025

Copy link
Copy Markdown
Contributor

See #29782 (comment)

PR summary

PR checklist

  • "closes #0000" is in the body of the PR description to link the related issue
  • new and changed code is tested
  • Plotting related features are demonstrated in an example
  • New Features and API Changes are noted with a directive and release note
  • Documentation complies with general and docstring guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@anntzer anntzer added the Documentation label Mar 31, 2025
@github-actions github-actions Bot added topic: pyplot API Documentation: user guide files in galleries/users_explain or doc/users labels Mar 31, 2025
@anntzer
anntzer force-pushed the close branch from be527dc to a6c8326 Compare March 31, 2025 11:14
dstansby
dstansby reviewed Mar 31, 2025
View reviewed changes
Comment thread lib/matplotlib/pyplot.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@anntzer
anntzer force-pushed the close branch from a6c8326 to d35988e Compare March 31, 2025 13:20
jklymak
jklymak reviewed Mar 31, 2025
View reviewed changes
Comment thread lib/matplotlib/pyplot.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@anntzer
anntzer force-pushed the close branch from d35988e to c5bd424 Compare March 31, 2025 19:34
jklymak
jklymak approved these changes Mar 31, 2025
View reviewed changes
timhoffm
timhoffm reviewed Apr 1, 2025
View reviewed changes
Comment thread lib/matplotlib/pyplot.py Outdated
Comment on lines +1190 to +1192
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`).

@timhoffm timhoffm Apr 1, 2025

Copy link
Copy Markdown
Member

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 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 by show() automatically deregisters the figure. For all other use cases, most prominently savefig() without show(), the figure must be deregistered explicitly using close().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tacaswell reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@anntzer anntzer Apr 1, 2025

Copy link
Copy Markdown
Contributor Author

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@anntzer
Improve docs regarding plt.close().
eea529e
@anntzer
anntzer force-pushed the close branch from c5bd424 to eea529e Compare April 1, 2025 08:24
timhoffm
timhoffm approved these changes Apr 1, 2025
View reviewed changes
@timhoffm

timhoffm commented Apr 1, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@timhoffm timhoffm added this to the v3.10.2 milestone Apr 1, 2025
@timhoffm
timhoffm merged commit 90385b4 into matplotlib:main Apr 1, 2025
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Apr 1, 2025
@timhoffm @meeseeksmachine
Backport PR matplotlib#29839: Improve docs regarding plt.close().
5fde149
@meeseeksmachine meeseeksmachine mentioned this pull request Apr 1, 2025
Backport PR #29839 on branch v3.10.x (Improve docs regarding plt.close().) #29848
Merged
@anntzer
anntzer deleted the close branch April 1, 2025 11:49
timhoffm added a commit that referenced this pull request Apr 1, 2025
@timhoffm
Merge pull request #29848 from meeseeksmachine/auto-backport-of-pr-29…
ba588a5
…839-on-v3.10.x

Backport PR #29839 on branch v3.10.x (Improve docs regarding plt.close().)
@ksunden ksunden mentioned this pull request May 9, 2025
merge up 3.10.3 #30031
Closed
5 tasks
@ksunden ksunden mentioned this pull request Jul 25, 2025
Manual Backport PR #30195 on branch v3.10.x (ci: Enable wheel builds on Python 3.14) #30356
Merged
5 tasks
@ksunden ksunden mentioned this pull request Aug 7, 2025
merge up v3.10.5 #30401
Merged
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dstansby dstansby dstansby left review comments
@jklymak jklymak jklymak approved these changes
@timhoffm timhoffm timhoffm approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

Documentation: user guide files in galleries/users_explain or doc/users Documentation topic: pyplot API

Projects

None yet

Milestone

v3.10.3

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@anntzer @timhoffm @jklymak @dstansby
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.