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

Skip to content

Commit 202a5f9

Browse files
committed
Remove "Use show()" from how-to and move relevant content to show() doscstring
1 parent fb0c10d commit 202a5f9

File tree

2 files changed

+27
-69
lines changed

2 files changed

+27
-69
lines changed

doc/faq/howto_faq.rst

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -436,64 +436,6 @@ the desired format::
436436
:doc:`/gallery/user_interfaces/web_application_server_sgskip` for
437437
information about running matplotlib inside of a web application.
438438

439-
.. _howto-show:
440-
441-
Use :func:`~matplotlib.pyplot.show`
442-
-----------------------------------
443-
444-
When you want to view your plots on your display,
445-
the user interface backend will need to start the GUI mainloop.
446-
This is what :func:`~matplotlib.pyplot.show` does. It tells
447-
Matplotlib to raise all of the figure windows created so far and start
448-
the mainloop. Because this mainloop is blocking by default (i.e., script
449-
execution is paused), you should only call this once per script, at the end.
450-
Script execution is resumed after the last window is closed. Therefore, if
451-
you are using Matplotlib to generate only images and do not want a user
452-
interface window, you do not need to call ``show`` (see :ref:`howto-batch`
453-
and :ref:`what-is-a-backend`).
454-
455-
.. note::
456-
Because closing a figure window unregisters it from pyplot, you must call
457-
`~matplotlib.pyplot.savefig` *before* calling ``show`` if you wish to save
458-
the figure as well as view it.
459-
460-
Whether ``show`` blocks further execution of the script or the python
461-
interpreter depends on whether Matplotlib is set to use interactive mode.
462-
In non-interactive mode (the default setting), execution is paused
463-
until the last figure window is closed. In interactive mode, the execution
464-
is not paused, which allows you to create additional figures (but the script
465-
won't finish until the last figure window is closed).
466-
467-
Because it is expensive to draw, you typically will not want Matplotlib
468-
to redraw a figure many times in a script such as the following::
469-
470-
plot([1, 2, 3]) # draw here?
471-
xlabel('time') # and here?
472-
ylabel('volts') # and here?
473-
title('a simple plot') # and here?
474-
show()
475-
476-
However, it is *possible* to force Matplotlib to draw after every command,
477-
which might be what you want when working interactively at the
478-
python console (see :ref:`mpl-shell`), but in a script you want to
479-
defer all drawing until the call to ``show``. This is especially
480-
important for complex figures that take some time to draw.
481-
:func:`~matplotlib.pyplot.show` is designed to tell Matplotlib that
482-
you're all done issuing commands and you want to draw the figure now.
483-
484-
.. note::
485-
486-
:func:`~matplotlib.pyplot.show` should typically only be called at
487-
most once per script and it should be the last line of your
488-
script. At that point, the GUI takes control of the interpreter.
489-
If you want to force a figure draw, use
490-
:func:`~matplotlib.pyplot.draw` instead.
491-
492-
.. versionadded:: v1.0.0
493-
Matplotlib 1.0.0 and 1.0.1 added support for calling ``show`` multiple times
494-
per script, and harmonized the behavior of interactive mode, across most
495-
backends.
496-
497439
.. _how-to-threads:
498440

499441
Working with threads

lib/matplotlib/pyplot.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,29 +315,45 @@ def show(*args, **kwargs):
315315
"""
316316
Display all open figures.
317317
318-
In non-interactive mode, *block* defaults to True. All figures
319-
will display and show will not return until all windows are closed.
320-
If there are no figures, return immediately.
321-
322-
In interactive mode *block* defaults to False. This will ensure
323-
that all of the figures are shown and this function immediately returns.
324-
325318
Parameters
326319
----------
327320
block : bool, optional
321+
Whether to wait for all figures to be closed before returning.
328322
329-
If `True` block and run the GUI main loop until all windows
323+
If `True` block and run the GUI main loop until all figure windows
330324
are closed.
331325
332-
If `False` ensure that all windows are displayed and return
326+
If `False` ensure that all figure windows are displayed and return
333327
immediately. In this case, you are responsible for ensuring
334328
that the event loop is running to have responsive figures.
335329
330+
Defaults to True in non-interactive mode and to False in interactive
331+
mode (see `.pyplot.isinteractive`).
332+
336333
See Also
337334
--------
338-
ion : enable interactive mode
339-
ioff : disable interactive mode
335+
ion : Enable interactive mode, which shows / updates the figure after
336+
every plotting command, so that calling ``show()`` is not necessary.
337+
ioff : Disable interactive mode.
338+
savefig : Save the figure to an image file instead of showing it on screen.
339+
340+
Notes
341+
-----
342+
**Saving figures to file and showing a window at the same time**
343+
344+
If you want an image file as well as a user interface window, use
345+
`.pyplot.savefig` before `.pyplot.show`. At the end of (a blocking)
346+
``show()`` the figure is closed and thus unregistered from pyplot. Calling
347+
`.pyplot.savefig` afterwards would save a new and thus empty figure. This
348+
limitation of command order does not apply if the show is non-blocking or
349+
if you keep a reference to the figure and use `.Figure.savefig`.
350+
351+
**Auto-show in jupyter notebooks**
340352
353+
The jupyter backends (activated via ``%matplotlib inline``,
354+
``%matplotlib notebook``, or ``%matplotlib widget``), call ``show()`` at
355+
the end of every cell by default. Thus, you usually don't have to call it
356+
explicitly there.
341357
"""
342358
_warn_if_gui_out_of_main_thread()
343359
return _backend_mod.show(*args, **kwargs)

0 commit comments

Comments
 (0)