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

Skip to content

Commit e85e53c

Browse files
committed
Reuse the noninteractivity warning from Figure.show in _Backend.show.
Currently, the warning message "Matplotlib is currently using ..., which is a non-GUI backend, so cannot show the figure" and the (minor) associated logic (of catching NonGuiException) is duplicated between Figure.show and _Backend.show. Make the latter use the former, to deduplicate it.
1 parent b5b9a63 commit e85e53c

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,8 @@ def show(cls, block=None):
185185
if not managers:
186186
return
187187
for manager in managers:
188-
try:
189-
manager.show()
190-
except NonGuiException:
191-
warnings.warn(
192-
('matplotlib is currently using %s, which is a ' +
193-
'non-GUI backend, so cannot show the figure.')
194-
% get_backend())
195-
return
188+
# Emits a warning if the backend is non-interactive.
189+
manager.canvas.figure.show()
196190
if cls.mainloop is None:
197191
return
198192
if block is None:

lib/matplotlib/figure.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,9 @@ def show(self, warn=True):
439439
except NonGuiException:
440440
pass
441441
if warn:
442-
warnings.warn(
443-
('matplotlib is currently using %s, which is a ' +
444-
'non-GUI backend, so cannot show the figure.')
445-
% get_backend())
442+
warnings.warn('Matplotlib is currently using %s, which is a '
443+
'non-GUI backend, so cannot show the figure.'
444+
% get_backend())
446445

447446
def _get_axes(self):
448447
return self._axstack.as_list()

0 commit comments

Comments
 (0)