- To show during interactive use or in a script:
plt.show()will show all figures that have been created by pyplot that have note beenplt.close()d. plt.show(block=False)will show the current figure, but continue the script.- works with
inline - works with ipympl
- easy to show all plots.
- mixed in with rest of
pyplot - too many figures open; must manually close the ones we don't want anymore or memory grows. For a large jupyter notebook with cells executed many times, this can actually be substantial.
- cannot do
fig.show(), but can dofig.savefig() - does not display anything in either
inlineoripympl
figwill be garbage collected because there are no references stored in a registry
- no way to show the figure on a GUI backend (no promotion possible).
- ugly import.
import matplotlib.mpl_gui as mg; fig, ax = mg.subplots()- Can be shown, but with new
mg.show([fig])(though singleton fig could trivially be added). - jupyter: works without
showinipympl; does not (currently) work (at all) withinline.
- no global state - garbage collection on dereferenced figures
- no connection to pyplot state-based interface
- New import and documentation (inertia relative to pyplot)
mg.show()doesn't know what figures to show, so it must be supplied a list of figures.- sometimes we create figures in loops, and assigning a different variable name to each figure to stop if from being dereferenced could be cumbersome.
import matplotlib.mpl_gui.registry as mr; fig, ax = mr.subplots()- allows
mr.show()to be exactly the same asplt.show.
- no connection to pyplot state-based interface
- exactly same as previous pyplot interface for this type of work.
- figures must be explicitly closed
This is between the two extremes, where there is no global registry, but a registry is maintained for a series of plots within a context:
with mg.FigureContext() as fc:
fig, ax = fc.subplots()
fig, ax = fc.subplot_mosaic('AA\nBC')
fig = fc.figure
makes three figures and shows them in a blocking manner, and then removes the registry on completion.
The question arose as to whether these should be top level imports eg fig, ax = mpl.subplots() A choice would need to be made as to whether that is the registry or non-registry version of the new interface.