Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Warn when calling "show" in a non-GUI backend, and provide a convenie…

…nt way to suppress the warning.
  • Loading branch information...
commit 58425248e38956a9aa276e1913d23476d469c5ec 1 parent 7a9c7d4
@mdboom authored
View
18 lib/matplotlib/__init__.py
@@ -1034,6 +1034,24 @@ def get_backend():
"Returns the current backend."
return rcParams['backend']
+
+class NonGUIBackendWarning(Warning):
+ pass
+
+
+def _warn_non_gui_show():
+ warnings.warn(
+ "matplotlib is currently using a non-GUI backend, "
+ "so the figure can not be shown. Call "
+ "matplotlib.hide_show_warnings() to suppress "
+ "these warnings.",
+ NonGUIBackendWarning)
+
+
+def hide_show_warnings():
+ warnings.simplefilter('ignore', NonGUIBackendWarning)
+
+
def interactive(b):
"""
Set interactive mode to boolean b.
View
3  lib/matplotlib/backend_bases.py
@@ -39,6 +39,7 @@
from matplotlib import rcParams
from matplotlib import is_interactive
from matplotlib._pylab_helpers import Gcf
+from matplotlib import _warn_non_gui_show
from matplotlib.transforms import Bbox, TransformedBbox, Affine2D
import cStringIO
@@ -2435,7 +2436,7 @@ def show(self):
"""
For GUI backends, show the figure window and redraw.
"""
- pass
+ _warn_non_gui_show()
def destroy(self):
pass
View
14 lib/matplotlib/figure.py
@@ -39,6 +39,7 @@
from matplotlib.text import Text, _process_text_args
from matplotlib.transforms import (Affine2D, Bbox, BboxTransformTo,
TransformedBbox)
+from matplotlib import _warn_non_gui_show
docstring.interpd.update(projection_names = get_projection_names())
@@ -334,13 +335,12 @@ def show(self):
For non-GUI backends, this does nothing.
"""
- manager = getattr(self.canvas, 'manager')
- if manager is not None:
- manager.show()
- import warnings
- warnings.warn(
- "matplotlib is currently using a non-GUI backend, "
- "so can not show the figure")
+ if hasattr(self, 'canvas'):
+ manager = getattr(self.canvas, 'manager', None)
+ if manager is not None:
+ manager.show()
+ return
+ _warn_non_gui_show()
def _get_axes(self):
return self._axstack.as_list()
Please sign in to comment.
Something went wrong with that request. Please try again.