Repository navigation
Commit 2980caa
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 c05537d commit 2980caa
1 file changed
Lines changed: 14 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2300 | 2300 | | |
2301 | 2301 | | |
2302 | 2302 | | |
2303 | | - | |
2304 | | - | |
2305 | | - | |
2306 | | - | |
2307 | | - | |
2308 | | - | |
| 2303 | + | |
2309 | 2304 | | |
2310 | | - | |
2311 | | - | |
2312 | | - | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
| 2314 | + | |
2313 | 2315 | | |
2314 | 2316 | | |
2315 | 2317 | | |
| |||
3264 | 3266 | | |
3265 | 3267 | | |
3266 | 3268 | | |
3267 | | - | |
| 3269 | + | |
3268 | 3270 | | |
3269 | 3271 | | |
3270 | 3272 | | |
3271 | 3273 | | |
3272 | 3274 | | |
3273 | 3275 | | |
3274 | 3276 | | |
3275 | | - | |
| 3277 | + | |
| 3278 | + | |
3276 | 3279 | | |
3277 | 3280 | | |
3278 | 3281 | | |
| |||
0 commit comments