-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Native support for showing OOP-created figures #19956
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
Comments
See #14024, perhaps. |
OK, then I'd be totally fine with something like |
I have some worries about making from matplotlib.figure import Figure
import matplotlib.pyplot as plt
fig = Figure()
plt.show(fig) work. The first is that if you create an empty figure it has an If you want to do the "promation" your self you can do m = plt.new_figure_manager_given_figure(0, fig) and then you will be able to I'm more inclined to go with something @anntzer suggested a while ago which is to add a At the end of the day, once you show a figure on screen you have converted your innocent Python script into a full-blown GUI application! The pyplot machinery does a remarkably good job at hiding this from most users on one hand and on the other we give users the tools to embed Matplotlib in a full-blown GUI of their design. I am not fully sold that there is much space in the middle where we can continue to hide the details of there being a GUI application from the user and let the users out from the oversight of pyplot. |
Thanks @tacaswell. We should pin this answer. |
This is not correct,
It would seem reasonable to promote Also, while users can do whatever they want (...), I think people passing Qt canvases to a Gtk event loop is quite rare... and again we can just explode in that case.
Ditto.
Again, we can check based on
That's fine too, but note that here again you have to decide what to do if a noncompatible (or noninteractive) canvas is already installed. |
This is like the third time I have gotten that wrong 😞 🐑 . I'll remember it correctly one of these days...
fair, but feels less odd to me to do that promotion / error checking / ... as a one-off "please take ownership of this figure" rather than "please show and maybe adopt this figure". There is also the issue that if you are mixing We also recently made @edmundsj I want to stress that despite my verbose and relatively skeptical/negative responses this is a very reasonable request. |
Actually I made |
Maybe we should discuss this on the call. We seem to have a tension between keep-it-simple and adding more flexibility. My naive take is that |
I am slowly convincing myself that @anntzer is right, but still have doubts. |
For the sake of comparison, pyvista does it like this: import pyvista as pv
p = pv.Plotter()
cyl = pv.Cylinder()
p.add_mesh(cyl)
p.show() As a library author, this is very convenient for me: I create a def fun_from_my_library():
import pyvista as pv
p = pv.Plotter()
# generate a fancy plot
return p
fun_from_my_library().show()
# or
fun_from_my_library().save("out.png")
# or ... The same works with mpl I gather from the above discussion that some might rather want to see |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
This turned into https://github.com/matplotlib/mpl-gui |
Uh oh!
There was an error while loading. Please reload this page.
Problem
Often, I will create figures using matplotlib using the
Figure
class explicitly, because either I want to make a figure and repeatedly tweak it to see how it looks, or I am creating a lot of figures and don't need / want to deal with the pyplot interface. However, as far as I can tell, there is no native matplotlib way to show those figures since they weren't created with the pyplot interface.An example of what I would like to do:
Error:
The reason I don't want to use
plt.subplots()
followed byplt.show()
, is, as mentioned above, because I often want to close and re-show the same figure. It seems really odd to me that matplotlib has a way of creating figures via a pure-OOP interface, but no easy way to display them. This is very frustrating and basically leads me to either repeatedly re-create the same plot with the pyplot interface instead of just tweaking the one I already have. I wrote a very hacky method for showing created figures based on a StackOverflow answer to this question which is below, and does not work reliably (the figure doubles in size every time I show it):Proposed Solution
Either support
fig.show()
directly for figures created using the OOP-interface, or provide a method likepyplot.show_figure()
which takes as an argument an existing figure and prints it to the screen (doing the exact same thing that aplt.plot()
followed byplt.show()
would do)The text was updated successfully, but these errors were encountered: