You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now, if one does not want to use pyplot (e.g., batch use), one can
do
from matplotlib.figure import Figure
fig = Figure(); ... <plot> ...; fig.savefig(...)
but it is impossible to show() the figure interactively (i.e. pyplot
cannot "adopt" the figure) e.g. for debugging.
This patch makes it possible: with it, one can do
fig = plt.new_figure_manager(num).canvas.figure
... <plot> ...
fig.savefig()
plt.show(figures=[fig])
Note that this does *not* register the figure with pyplot; in particular
*fig* is garbage-collected when it goes out of scope, does not
participate in gcf(); etc. So this is "pyplotless" in the sense that
there is no global figure registry anymore, but pyplot still stays in
charge of the GUI integration.
Obviously the `plt.new_figure_manager(num).canvas.figure` expression
could / should be encapsulated in a helper function, up to bikeshedding.
The `num` parameter is needed as matplotlib currently uses it to set the
figure title, but that can easily be made optional too.
Finally note that `plt.show([fig])` would be a nicer API, but right now
the first parameter to plt.show is `block`, which is undergoing
transition to kwonly.
IOW the end-goal would be e.g.
# intentionally terrible name as placeholder :)
fig = plt.new_figure_not_globally_registered("some title")
... <plot> ...
fig.savefig()
plt.show([fig])
0 commit comments