8000 Backport PR #15751: Modernize FAQ entry for plt.show(). · matplotlib/matplotlib@d05f12e · GitHub
[go: up one dir, main page]

Skip to content

Commit d05f12e

Browse files
timhoffmMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #15751: Modernize FAQ entry for plt.show().
1 parent d10da59 commit d05f12e

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
@@ -482,39 +482,26 @@ interface window, you do not need to call ``show`` (see :ref:`howto-batch`
482482
and :ref:`what-is-a-backend`).
483483

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

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

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

511-
plot([1,2,3]) # draw here ?
512-
xlabel('time') # and here ?
513-
ylabel('volts') # and here ?
514-
title('a simple plot') # and here ?
499+
plot([1, 2, 3]) # draw here?
500+
xlabel('time') # and here?
501+
ylabel('volts') # and here?
502+
title('a simple plot') # and here?
515503
show()
516504

517-
518505
However, it is *possible* to force Matplotlib to draw after every command,
519506
which might be what you want when working interactively at the
520507
python console (see :ref:`mpl-shell`), but in a script you want to
@@ -531,26 +518,10 @@ you're all done issuing commands and you want to draw the figure now.
531518
If you want to force a figure draw, use
532519
:func:`~matplotlib.pyplot.draw` instead.
533520

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

555526
.. _howto-boxplot_violinplot:
556527

0 commit comments

Comments
 (0)
0