-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
base: main
Are you sure you want to change the base?
Conversation
0e13c82
to
56f4ee1
Compare
56f4ee1
to
f97c262
Compare
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 😕 |
This would also close #19956. |
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)
When destroying a manager, replace the figure's canvas by a figure canvas base.
f97c262
to
d0958e4
Compare
Showing again now works properly. When destroying a figure manager, the figure's canvas is reset to a FigureCanvasBase. Technical questions:
|
Note: the failing tests are in matplotlib/lib/matplotlib/tests/test_backends_interactive.py Lines 222 to 235 in 011d12f
This is now no longer the case, as closing the figure resets the canvas to ![]() How should we handle this? I'm inclined to say that the previous expectation is no longer justified, and it makes sense that the canvas is reset. Should we try to fix this with tolerances? Or don't we need this image test at all anymore and instead it is sufficient to test that the figure has again a |
It's a bit strange that the end png result is not the same, as both should ultimately go through Agg for rasterizing... It would be nice to figure out what is going wrong, but I agree this isn't a blocker. |
Failing tests are
and the same again for toolmanager, which I left out for simplicity. So all cairocffi tests fail and addtionally the qtagg-PyQt5 test. But the agg-based tests for PyQt6, PySide2 and PySide6 pass. Interestingly, the qtagg-PyQt5 test passes on my local machine. The above diff image was from qtcairo-PyQt5. |
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
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.