Permalink
Browse files

Add a "show" method to figures that don't have a GUI backend. Fixed #835

.
  • Loading branch information...
1 parent 9892758 commit 7a9c7d4e4ebae4d095c446fd9f79e0be62b1bdc6 @mdboom committed Aug 20, 2012
Showing with 23 additions and 3 deletions.
  1. +9 −3 lib/matplotlib/backend_bases.py
  2. +14 −0 lib/matplotlib/figure.py
View
12 lib/matplotlib/backend_bases.py
@@ -2423,14 +2423,20 @@ 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.
+ """
+ pass
+
def destroy(self):
pass
View
14 lib/matplotlib/figure.py
@@ -328,6 +328,20 @@ 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.
+ """
+ manager = getattr(self.canvas, 'manager')
@WeatherGod
WeatherGod added a line comment Aug 29, 2012

Also, is this test a guarantee test of gui-ness? Furthermore, how would ipython's custom backend behave here for the ipython notebook?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if manager is not None:
+ manager.show()
+ import warnings
@WeatherGod
WeatherGod added a line comment Aug 29, 2012

The warning would always execute. Did you mean to put an "else" here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ warnings.warn(
+ "matplotlib is currently using a non-GUI backend, "
+ "so can not show the figure")
+
def _get_axes(self):
return self._axstack.as_list()

0 comments on commit 7a9c7d4

Please sign in to comment.