Commit cfd768e
committed
Simpler "pyplotless" use pattern.
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])1 parent 5ba3911 commit cfd768e
1 file changed
Lines changed: 17 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2485 | 2485 | | |
2486 | 2486 | | |
2487 | 2487 | | |
2488 | | - | |
2489 | | - | |
2490 | | - | |
2491 | | - | |
2492 | | - | |
2493 | | - | |
| 2488 | + | |
2494 | 2489 | | |
2495 | | - | |
2496 | | - | |
2497 | | - | |
| 2490 | + | |
2498 | 2491 | | |
2499 | 2492 | | |
2500 | 2493 | | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
| 2500 | + | |
| 2501 | + | |
| 2502 | + | |
| 2503 | + | |
| 2504 | + | |
2501 | 2505 | | |
2502 | 2506 | | |
2503 | 2507 | | |
| |||
3545 | 3549 | | |
3546 | 3550 | | |
3547 | 3551 | | |
3548 | | - | |
| 3552 | + | |
3549 | 3553 | | |
3550 | | - | |
| 3554 | + | |
3551 | 3555 | | |
3552 | 3556 | | |
3553 | 3557 | | |
3554 | 3558 | | |
3555 | 3559 | | |
3556 | | - | |
| 3560 | + | |
| 3561 | + | |
3557 | 3562 | | |
3558 | 3563 | | |
3559 | 3564 | | |
| |||
0 commit comments