Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6870ac0

Browse filesBrowse files
authored
Merge pull request #15341 from anntzer/nonguiexception
Move non-gui warning message to backend_bases.
2 parents 59762d4 + 154a616 commit 6870ac0
Copy full SHA for 6870ac0

File tree

Expand file treeCollapse file tree

2 files changed

+14
-12
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-12
lines changed

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+12-6Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,11 +2563,15 @@ def notify_axes_change(fig):
25632563
def show(self):
25642564
"""
25652565
For GUI backends, show the figure window and redraw.
2566-
For non-GUI backends, raise an exception to be caught
2567-
by :meth:`~matplotlib.figure.Figure.show`, for an
2568-
optional warning.
2566+
For non-GUI backends, raise an exception, unless running headless (i.e.
2567+
on Linux with an unset DISPLAY); this exception is converted to a
2568+
warning in `.Figure.show`.
25692569
"""
2570-
raise NonGuiException()
2570+
# This should be overridden in GUI backends.
2571+
if mpl.backends._get_running_interactive_framework() != "headless":
2572+
raise NonGuiException(
2573+
f"Matplotlib is currently using {get_backend()}, which is "
2574+
f"a non-GUI backend, so cannot show the figure.")
25712575

25722576
def destroy(self):
25732577
pass
@@ -3360,8 +3364,10 @@ def show(cls, block=None):
33603364
if not managers:
33613365
return
33623366
for manager in managers:
3363-
# Emits a warning if the backend is non-interactive.
3364-
manager.canvas.figure.show()
3367+
try:
3368+
manager.show() # Emits a warning for non-interactive backend.
3369+
except NonGuiException as exc:
3370+
cbook._warn_external(str(exc))
33653371
if cls.mainloop is None:
33663372
return
33673373
if block is None:

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,8 @@ def show(self, warn=True):
436436
"normally created by pyplot.figure()")
437437
try:
438438
self.canvas.manager.show()
439-
except NonGuiException:
440-
if (backends._get_running_interactive_framework() != "headless"
441-
and warn):
442-
cbook._warn_external(
443-
f"Matplotlib is currently using {get_backend()}, which is "
444-
f"a non-GUI backend, so cannot show the figure.")
439+
except NonGuiException as exc:
440+
cbook._warn_external(str(exc))
445441

446442
def _get_axes(self):
447443
return self._axstack.as_list()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.