Skip to content

Doc changes to plt.show #11720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/matplotlib/backends/backend_webagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,10 @@ def trigger_manager_draw(manager):
manager.canvas.draw_idle()

@staticmethod
def show():
def show(block=True):
if not block:
block = True

WebAggApplication.initialize()

url = "http://127.0.0.1:{port}{prefix}".format(
Expand Down
56 changes: 43 additions & 13 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,24 +230,54 @@ def switch_backend(newbackend):
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()


def show(*args, **kw):
def show(block=None):
"""
Display a figure.
When running in ipython with its pylab mode, display all
figures and return to the ipython prompt.
Draw and display all figures.

In non-interactive mode, display all figures and block until
the figures have been closed; in interactive mode it has no
effect unless figures were created prior to a change from
non-interactive to interactive mode (not recommended). In
that case it displays the figures but does not block.
Mainly used in non-interactive mode to draw and display
the figures. It usually does nothing in interactive mode.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would it not do anything in interactive mode? I think it also shows the figure there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure. It was written in the old docstring that it does nothing.

When I test it in spyder, the only difference is that the "thumbnail" in the toolbar start to blink if plt.show() is used. The figure window don't pop up to the front or something like that.


A single experimental keyword argument, *block*, may be
set to True or False to override the blocking behavior
described above.
Parameters
----------

block : bool or None
True means that the execution is blocked until the figures are closed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be shortend: "Whether the execution is blocked until the figures are closed."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative suggestion:

If True, the execution is blocked until all displayed figures are closed. If False, the python execution continues after the figures are displayed.

and False means that the python execution continues after the figures
are displayed.

The default behavior is different in interactive and non-interactive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shorter:

The default is True unless interactive mode is enabled or %matplotlib_ is used in IPython.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't want to go for the long version here. It's just redundant and doesn't add to the clarity.

mode and whether or not `%matplotlib`_ is used in IPython. The default
is False in interactive mode and True in non-interactive mode except
when `%matplotlib`_ has been used in IPython, it is False in that case.

Notes
-----
Blocking is necessary when running ``python script.py`` to be able to see
the figures before the python session finish but blocking is often not the
expected behavior when running Python interactively.

The difference between non-interactive and interactive mode is that the
figures are drawn and updated automatically after each plot command in
interactive mode.

Interactive mode can be set on and off with `.pyplot.ion` and
`.pyplot.ioff` in both vanilla Python and IPython and set to on with
`%matplotlib`_ in IPython.

.. _`%matplotlib`:
http://ipython.readthedocs.io/en/stable/interactive/plotting.html#id1

See Also
--------
.pyplot.ion
.pyplot.ioff
.pyplot.isinteractive
"""
global _show
return _show(*args, **kw)
if block is not None:
if type(block) != bool:
raise TypeError('"block" should be a bool or None')
return _show(block=block)


def isinteractive():
Expand Down