diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index b3b3c59cb2b7..61b2e3b79333 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -185,14 +185,8 @@ def show(cls, block=None): if not managers: return for manager in managers: - try: - manager.show() - except NonGuiException: - warnings.warn( - ('matplotlib is currently using %s, which is a ' + - 'non-GUI backend, so cannot show the figure.') - % get_backend()) - return + # Emits a warning if the backend is non-interactive. + manager.canvas.figure.show() if cls.mainloop is None: return if block is None: diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index b97655e8fb39..c6cd6ce44794 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -439,10 +439,9 @@ def show(self, warn=True): except NonGuiException: pass if warn: - warnings.warn( - ('matplotlib is currently using %s, which is a ' + - 'non-GUI backend, so cannot show the figure.') - % get_backend()) + warnings.warn('Matplotlib is currently using %s, which is a ' + 'non-GUI backend, so cannot show the figure.' + % get_backend()) def _get_axes(self): return self._axstack.as_list() diff --git a/lib/matplotlib/tests/test_backend_bases.py b/lib/matplotlib/tests/test_backend_bases.py index 244c9a36b1fe..cd8db6bc08ef 100644 --- a/lib/matplotlib/tests/test_backend_bases.py +++ b/lib/matplotlib/tests/test_backend_bases.py @@ -69,13 +69,11 @@ def test_non_gui_warning(): with pytest.warns(UserWarning) as rec: plt.show() assert len(rec) == 1 - assert 'matplotlib is currently using pdf, ' \ - 'which is a non-GUI backend' \ - in str(rec[0].message) + assert ('Matplotlib is currently using pdf, which is a non-GUI backend' + in str(rec[0].message)) with pytest.warns(UserWarning) as rec: plt.gcf().show() assert len(rec) == 1 - assert 'matplotlib is currently using pdf, ' \ - 'which is a non-GUI backend' \ - in str(rec[0].message) + assert ('Matplotlib is currently using pdf, which is a non-GUI backend' + in str(rec[0].message))