Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6134308

Browse files
timhoffmMeeseeksDev[bot]
authored andcommitted
Backport PR #15751: Modernize FAQ entry for plt.show().
1 parent ecb5233 commit 6134308

1 file changed

Lines changed: 13 additions & 42 deletions

File tree

doc/faq/howto_faq.rst

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -455,39 +455,26 @@ interface window, you do not need to call ``show`` (see :ref:`howto-batch`
455455
and :ref:`what-is-a-backend`).
456456

457457
.. note::
458-
Because closing a figure window invokes the destruction of its plotting
459-
elements, you should call :func:`~matplotlib.pyplot.savefig` *before*
460-
calling ``show`` if you wish to save the figure as well as view it.
458+
Because closing a figure window unregisters it from pyplot, you must call
459+
`~matplotlib.pyplot.savefig` *before* calling ``show`` if you wish to save
460+
the figure as well as view it.
461461

462-
.. versionadded:: v1.0.0
463-
``show`` now starts the GUI mainloop only if it isn't already running.
464-
Therefore, multiple calls to ``show`` are now allowed.
465-
466-
Having ``show`` block further execution of the script or the python
467-
interpreter depends on whether Matplotlib is set for interactive mode
468-
or not. In non-interactive mode (the default setting), execution is paused
462+
Whether ``show`` blocks further execution of the script or the python
463+
interpreter depends on whether Matplotlib is set to use interactive mode.
464+
In non-interactive mode (the default setting), execution is paused
469465
until the last figure window is closed. In interactive mode, the execution
470466
is not paused, which allows you to create additional figures (but the script
471467
won't finish until the last figure window is closed).
472468

473-
.. note::
474-
Support for interactive/non-interactive mode depends upon the backend.
475-
Until version 1.0.0 (and subsequent fixes for 1.0.1), the behavior of
476-
the interactive mode was not consistent across backends.
477-
As of v1.0.1, only the macosx backend differs from other backends
478-
because it does not support non-interactive mode.
479-
480-
481469
Because it is expensive to draw, you typically will not want Matplotlib
482470
to redraw a figure many times in a script such as the following::
483471

484-
plot([1,2,3]) # draw here ?
485-
xlabel('time') # and here ?
486-
ylabel('volts') # and here ?
487-
title('a simple plot') # and here ?
472+
plot([1, 2, 3]) # draw here?
473+
xlabel('time') # and here?
474+
ylabel('volts') # and here?
475+
title('a simple plot') # and here?
488476
show()
489477

490-
491478
However, it is *possible* to force Matplotlib to draw after every command,
492479
which might be what you want when working interactively at the
493480
python console (see :ref:`mpl-shell`), but in a script you want to
@@ -504,26 +491,10 @@ you're all done issuing commands and you want to draw the figure now.
504491
If you want to force a figure draw, use
505492
:func:`~matplotlib.pyplot.draw` instead.
506493

507-
Many users are frustrated by ``show`` because they want it to be a
508-
blocking call that raises the figure, pauses the script until they
509-
close the figure, and then allow the script to continue running until
510-
the next figure is created and the next show is made. Something like
511-
this::
512-
513-
# WARNING : illustrating how NOT to use show
514-
for i in range(10):
515-
# make figure i
516-
show()
517-
518-
This is not what show does and unfortunately, because doing blocking
519-
calls across user interfaces can be tricky, is currently unsupported,
520-
though we have made significant progress towards supporting blocking events.
521-
522494
.. versionadded:: v1.0.0
523-
As noted earlier, this restriction has been relaxed to allow multiple
524-
calls to ``show``. In *most* backends, you can now expect to be
525-
able to create new figures and raise them in a subsequent call to
526-
``show`` after closing the figures from a previous call to ``show``.
495+
Matplotlib 1.0.0 and 1.0.1 added support for calling ``show`` multiple times
496+
per script, and harmonized the behavior of interactive mode, across most
497+
backends.
527498

528499
.. _howto-boxplot_violinplot:
529500

0 commit comments

Comments
 (0)