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

Skip to content

Commit 37190ec

Browse files
committed
Don't warn in show() when running a non-interactive backened headless.
On Linux, $DISPLAY is unset, then we can't run a GUI toolkit anyways, so don't warn about that in `show()`. Delete the Note in the docstring which was redundant with the Parameters entry.
1 parent 70a55db commit 37190ec

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

lib/matplotlib/figure.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import numpy as np
1919

2020
from matplotlib import rcParams
21-
from matplotlib import docstring
21+
from matplotlib import backends, docstring
2222
from matplotlib import __version__ as _mpl_version
2323
from matplotlib import get_backend
2424

@@ -415,12 +415,8 @@ def show(self, warn=True):
415415
Parameters
416416
----------
417417
warn : bool
418-
If ``True``, issue warning when called on a non-GUI backend
419-
420-
Notes
421-
-----
422-
For non-GUI backends, this does nothing, in which case a warning will
423-
be issued if *warn* is ``True`` (default).
418+
If ``True`` and we are not running headless (i.e. on Linux with an
419+
unset DISPLAY), issue warning when called on a non-GUI backend.
424420
"""
425421
try:
426422
manager = getattr(self.canvas, 'manager')
@@ -436,7 +432,8 @@ def show(self, warn=True):
436432
return
437433
except NonGuiException:
438434
pass
439-
if warn:
435+
if (backends._get_running_interactive_framework() != "headless"
436+
and warn):
440437
warnings.warn('Matplotlib is currently using %s, which is a '
441438
'non-GUI backend, so cannot show the figure.'
442439
% get_backend())

0 commit comments

Comments
 (0)