Skip to content

Reuse the noninteractivity warning from Figure.show in _Backend.show. #11305

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

Merged
merged 1 commit into from
May 25, 2018
Merged
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
10 changes: 2 additions & 8 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 4 additions & 6 deletions lib/matplotlib/tests/test_backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))