Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ENH: Allow to register standalone figures with pyplot #29855

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Apr 1, 2025

It may be fundamentally nice not to have to create the figure though pyplot to be able to use it in pyplot afterwards. You can now do

from matplotlib.figure import Figure
import matplotlib.pyplot as plt

fig = Figure()
fig.subplots().plot([1, 3, 2])

plt.figure(fig)  # fig is now tracked in pyplot
plt.show()

This also opens up the possibility to more dynamically track and untrack figures in pyplot, which opens up the road to optimized figure tracking in pyplot (#29849)

Anybody, feel free to play around with this and try to break it.

It may be fundamentally nice not to have to create the figure
though pyplot to be able to use it in pyplot afterwards. You can now do

```
from matplotlib.figure import Figure
import matplotlib.pyplot as plt

fig = Figure()
fig.subplots().plot([1, 3, 2])

plt.figure(fig)  # fig is now tracked in pyplot
plt.show()
```

This also opens up the possibility to more dynamically track
and untrack figures in pyplot, which opens up the road to
optimized figure tracking in pyplot (matplotlib#29849)
@timhoffm timhoffm force-pushed the pyplot-register-figure branch from 56f4ee1 to f97c262 Compare April 1, 2025 22:19
@rcomer
Copy link
Member

rcomer commented Apr 2, 2025

I was hoping I could modify the figure and show again, but that does not seem to be the case

import matplotlib.pyplot as plt
from matplotlib.figure import Figure

fig = Figure()
ax = fig.subplots()
ax.plot([0, 2])
plt.figure(fig)
plt.show()

ax.set_title('A cool line')
plt.figure(fig)
plt.show()

No title is shown 😕

@timhoffm timhoffm marked this pull request as draft April 2, 2025 11:34
@anntzer
Copy link
Contributor

anntzer commented May 1, 2025

This would also close #19956.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.