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

Skip to content

Commit 5390da3

Browse files
authored
Merge pull request #15751 from anntzer/showdocs
Modernize FAQ entry for plt.show().
2 parents 616d672 + 59f5cae commit 5390da3

File tree

1 file changed

+13
-42
lines changed

1 file changed

+13
-42
lines changed

doc/faq/howto_faq.rst

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

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

492-
.. versionadded:: v1.0.0
493-
``show`` now starts the GUI mainloop only if it isn't already running.
494-
Therefore, multiple calls to ``show`` are now allowed.
495-
496-
Having ``show`` block further execution of the script or the python
497-
interpreter depends on whether Matplotlib is set for interactive mode
498-
or not. In non-interactive mode (the default setting), execution is paused
492+
Whether ``show`` blocks further execution of the script or the python
493+
interpreter depends on whether Matplotlib is set to use interactive mode.
494+
In non-interactive mode (the default setting), execution is paused
499495
until the last figure window is closed. In interactive mode, the execution
500496
is not paused, which allows you to create additional figures (but the script
501497
won't finish until the last figure window is closed).
502498

503-
.. note::
504-
Support for interactive/non-interactive mode depends upon the backend.
505-
Until version 1.0.0 (and subsequent fixes for 1.0.1), the behavior of
506-
the interactive mode was not consistent across backends.
507-
As of v1.0.1, only the macosx backend differs from other backends
508-
because it does not support non-interactive mode.
509-
510-
511499
Because it is expensive to draw, you typically will not want Matplotlib
512500
to redraw a figure many times in a script such as the following::
513501

514-
plot([1,2,3]) # draw here ?
515-
xlabel('time') # and here ?
516-
ylabel('volts') # and here ?
517-
title('a simple plot') # and here ?
502+
plot([1, 2, 3]) # draw here?
503+
xlabel('time') # and here?
504+
ylabel('volts') # and here?
505+
title('a simple plot') # and here?
518506
show()
519507

520-
521508
However, it is *possible* to force Matplotlib to draw after every command,
522509
which might be what you want when working interactively at the
523510
python console (see :ref:`mpl-shell`), but in a script you want to
@@ -534,26 +521,10 @@ you're all done issuing commands and you want to draw the figure now.
534521
If you want to force a figure draw, use
535522
:func:`~matplotlib.pyplot.draw` instead.
536523

537-
Many users are frustrated by ``show`` because they want it to be a
538-
blocking call that raises the figure, pauses the script until they
539-
close the figure, and then allow the script to continue running until
540-
the next figure is created and the next show is made. Something like
541-
this::
542-
543-
# WARNING : illustrating how NOT to use show
544-
for i in range(10):
545-
# make figure i
546-
show()
547-
548-
This is not what show does and unfortunately, because doing blocking
549-
calls across user interfaces can be tricky, is currently unsupported,
550-
though we have made significant progress towards supporting blocking events.
551-
552524
.. versionadded:: v1.0.0
553-
As noted earlier, this restriction has been relaxed to allow multiple
554-
calls to ``show``. In *most* backends, you can now expect to be
555-
able to create new figures and raise them in a subsequent call to
556-
``show`` after closing the figures from a previous call to ``show``.
525+
Matplotlib 1.0.0 and 1.0.1 added support for calling ``show`` multiple times
526+
per script, and harmonized the behavior of interactive mode, across most
527+
backends.
557528

558529
.. _howto-boxplot_violinplot:
559530

0 commit comments

Comments
 (0)