Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

add documentation for figure show method in backend_bases and backend_template #835

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+42 −3
Split
View
@@ -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.
@@ -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
@@ -2423,13 +2424,19 @@ def __init__(self, canvas, num):
self.key_press)
"""
The returned id from connecting the default key handler via :meth:`FigureCanvasBase.mpl_connnect`.
-
+
To disable default key press handling::
-
+
manager, canvas = figure.canvas.manager, figure.canvas
canvas.mpl_disconnect(manager.key_press_handler_id)
-
+
+ """
+
+ def show(self):
+ """
+ For GUI backends, show the figure window and redraw.
@pelson

pelson Sep 1, 2012

Member

Because there is some monkey patching, this method is not called from the interactive backends, right? Perhaps this would be a good place to state this.

"""
+ _warn_non_gui_show()
def destroy(self):
pass
View
@@ -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())
@@ -328,6 +329,19 @@ def __init__(self,
self.clf()
self._cachedRenderer = None
+ def show(self):
+ """
+ If using a GUI backend, display the figure window.
+
+ For non-GUI backends, this does nothing.
+ """
+ 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()