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

Skip to content

Commit 339705c

Browse files
committed
Added significant information regarding the usage of the show() command.
1 parent 6a16eea commit 339705c

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

doc/faq/howto_faq.rst

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -464,17 +464,43 @@ pyplot::
464464
Use :func:`~matplotlib.pyplot.show`
465465
------------------------------------------
466466

467-
The user interface backends need to start the GUI mainloop, and this
468-
is what :func:`~matplotlib.pyplot.show` does. It tells matplotlib to
469-
raise all of the figure windows and start the mainloop. Because the
470-
mainloop is blocking, you should only call this once per script, at
471-
the end. If you are using matplotlib to generate images only and do
472-
not want a user interface window, you do not need to call ``show`` (see
473-
:ref:`howto-batch` and :ref:`what-is-a-backend`).
467+
When you want to view your plots on your display,
468+
the user interface backend will need to start the GUI mainloop.
469+
This is what :func:`~matplotlib.pyplot.show` does. It tells
470+
matplotlib to raise all of the figure windows created so far and start
471+
the mainloop. Because this mainloop is blocking (i.e., script execution is
472+
paused), you should only call this once per script, at the end. Script
473+
execution is resumed after the last window is closed. Therefore, if you are
474+
using matplotlib to generate only images and do not want a user interface
475+
window, you do not need to call ``show`` (see :ref:`howto-batch` and
476+
:ref:`what-is-a-backend`).
474477

478+
.. note::
479+
Because closing a figure window invokes the destruction of its plotting
480+
elements, you should call :func:`~matplotlib.pyplot.savefig` *before*
481+
calling ``show`` if you wish to save the figure as well as view it.
482+
483+
.. versionadded:: v1.0.0
484+
``show`` now starts the GUI mainloop only if it isn't already running.
485+
Therefore, multiple calls to ``show`` are now allowed.
475486

476-
Because it is expensive to draw, matplotlib does not want redraw the figure
477-
many times in a script such as the following::
487+
Having ``show`` block further execution of the script or the python
488+
interperator depends on whether matplotlib is set for interactive mode
489+
or not. In non-interactive mode (the default setting), execution is paused
490+
until the last figure window is closed. In interactive mode, the execution
491+
is not paused, which allows you to create additional figures (but the script
492+
won't finish until the last figure window is closed).
493+
494+
.. note::
495+
Support for interactive/non-interactive mode depends upon the backend.
496+
Until version 1.0.0 (and subsequent fixes for 1.0.1), the behavior of
497+
the interactive mode was not consistent across backends.
498+
As of v1.0.1, only the macosx backend differs from other backends
499+
because it does not support non-interactive mode.
500+
501+
502+
Because it is expensive to draw, you typically will not want matplotlib
503+
to redraw a figure many times in a script such as the following::
478504

479505
plot([1,2,3]) # draw here ?
480506
xlabel('time') # and here ?
@@ -483,24 +509,24 @@ many times in a script such as the following::
483509
show()
484510

485511

486-
It is *possible* to force matplotlib to draw after every command,
512+
However, it is *possible* to force matplotlib to draw after every command,
487513
which might be what you want when working interactively at the
488514
python console (see :ref:`mpl-shell`), but in a script you want to
489-
defer all drawing until the script has executed. This is especially
515+
defer all drawing until the call to ``show``. This is especially
490516
important for complex figures that take some time to draw.
491517
:func:`~matplotlib.pyplot.show` is designed to tell matplotlib that
492518
you're all done issuing commands and you want to draw the figure now.
493519

494520
.. note::
495521

496-
:func:`~matplotlib.pyplot.show` should be called at most once per
497-
script and it should be the last line of your script. At that
498-
point, the GUI takes control of the interpreter. If you want to
499-
force a figure draw, use :func:`~matplotlib.pyplot.draw` instead.
522+
:func:`~matplotlib.pyplot.show` should typically only be called
523+
at most once per script and it should be the last line of your script.
524+
At that point, the GUI takes control of the interpreter. If you want
525+
to force a figure draw, use :func:`~matplotlib.pyplot.draw` instead.
500526

501-
Many users are frustrated by show because they want it to be a
502-
blocking call that raises the figure, pauses the script until the
503-
figure is closed, and then allows the script to continue running until
527+
Many users are frustrated by ``show`` because they want it to be a
528+
blocking call that raises the figure, pauses the script until they
529+
close the figure, and then allow the script to continue running until
504530
the next figure is created and the next show is made. Something like
505531
this::
506532

@@ -511,7 +537,13 @@ this::
511537

512538
This is not what show does and unfortunately, because doing blocking
513539
calls across user interfaces can be tricky, is currently unsupported,
514-
though we have made some progress towards supporting blocking events.
540+
though we have made significant progress towards supporting blocking events.
541+
542+
.. versionadded:: v1.0.0
543+
As noted earlier, this restriction has been relaxed to allow multiple
544+
calls to ``show``. In *most* backends, you can now expect to be
545+
able to create new figures and raise them in a subsequent call to
546+
``show`` after closing the figures from a previous call to ``show``.
515547

516548

517549
.. _howto-contribute:

0 commit comments

Comments
 (0)