diff --git a/doc/api/next_api_changes/2018-05-06-DS.rst b/doc/api/next_api_changes/2018-05-06-DS.rst new file mode 100644 index 000000000000..d96128486ff8 --- /dev/null +++ b/doc/api/next_api_changes/2018-05-06-DS.rst @@ -0,0 +1,7 @@ +Default value for ``block`` keyword arg standardised to ``True`` +---------------------------------------------------------------- + +The ``block`` keyword argument that can be supplied to `.pyplot.show()` now +takes a default value of ``True`` instead of ``None``. The behaviour is +otherwise the same, and the `.backend_bases.FigureManagerBase.show()` has +also had this change applied. diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 030e21f7687f..8d076f2755d6 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -177,12 +177,11 @@ def draw_if_interactive(cls): cls.trigger_manager_draw(manager) @classmethod - def show(cls, block=None): + def show(cls, block=True): """Show all figures. - `show` blocks by calling `mainloop` if *block* is ``True``, or if it - is ``None`` and we are neither in IPython's ``%pylab`` mode, nor in - `interactive` mode. + `show` blocks by calling `mainloop` if *block* is ``True`` and we are + neither in IPython's ``%pylab`` mode, nor in `interactive` mode. """ managers = Gcf.get_all_fig_managers() if not managers: @@ -198,7 +197,7 @@ def show(cls, block=None): return if cls.mainloop is None: return - if block is None: + if block: # Hack: Are we in IPython's pylab mode? from matplotlib import pyplot try: @@ -210,8 +209,6 @@ def show(cls, block=None): block = not ipython_pylab and not is_interactive() # TODO: The above is a hack to get the WebAgg backend working with # ipython's `%pylab` mode until proper integration is implemented. - if get_backend() == "WebAgg": - block = True if block: cls.mainloop() @@ -244,7 +241,7 @@ class ShowBase(_Backend): Subclass must override mainloop() method. """ - def __call__(self, block=None): + def __call__(self, block=True): return self.show(block=block) @@ -2635,7 +2632,7 @@ def notify_axes_change(fig): if self.toolmanager is None and self.toolbar is not None: self.toolbar.update() - def show(self): + def show(self, block=True): """ For GUI backends, show the figure window and redraw. For non-GUI backends, raise an exception to be caught diff --git a/lib/matplotlib/backends/backend_nbagg.py b/lib/matplotlib/backends/backend_nbagg.py index 16d3d51e0a74..7300317675d7 100644 --- a/lib/matplotlib/backends/backend_nbagg.py +++ b/lib/matplotlib/backends/backend_nbagg.py @@ -242,7 +242,7 @@ def trigger_manager_draw(manager): manager.show() @staticmethod - def show(*args, **kwargs): + def show(block=True): ## TODO: something to do when keyword block==False ? from matplotlib._pylab_helpers import Gcf diff --git a/lib/matplotlib/backends/backend_template.py b/lib/matplotlib/backends/backend_template.py index 384a69850230..b7e44084fc46 100644 --- a/lib/matplotlib/backends/backend_template.py +++ b/lib/matplotlib/backends/backend_template.py @@ -172,7 +172,7 @@ def draw_if_interactive(): """ -def show(block=None): +def show(block=True): """ For image backends - is not required For GUI backends - show() is usually the last line of a pylab script and diff --git a/lib/matplotlib/backends/backend_webagg.py b/lib/matplotlib/backends/backend_webagg.py index 18a995b97619..2b9bae78a030 100644 --- a/lib/matplotlib/backends/backend_webagg.py +++ b/lib/matplotlib/backends/backend_webagg.py @@ -319,7 +319,10 @@ def trigger_manager_draw(manager): manager.canvas.draw_idle() @staticmethod - def show(): + def show(block=True): + if not block: + warnings.warn('The webagg backend does not support "block=False"') + block = True WebAggApplication.initialize() url = "http://127.0.0.1:{port}{prefix}".format( diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 2725094fe077..e4fd8ecbd9ed 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -231,9 +231,10 @@ def switch_backend(newbackend): _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() -def show(*args, **kw): +def show(block=True): """ Display a figure. + When running in ipython with its pylab mode, display all figures and return to the ipython prompt. @@ -243,12 +244,14 @@ def show(*args, **kw): non-interactive to interactive mode (not recommended). In that case it displays the figures but does not block. - A single experimental keyword argument, *block*, may be - set to True or False to override the blocking behavior - described above. + Parameters + ---------- + block : bool, optional + Experimental; set to ``False`` to override the blocking + behavior described above. """ global _show - return _show(*args, **kw) + return _show(block=block) def isinteractive():