Permalink
Browse files

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

.
  • Loading branch information...
mdboom authored and efiring committed Aug 20, 2012
1 parent 0f9f85f commit faafa59fa216861dff574717de37fdeeeb646cbe
Showing with 22 additions and 2 deletions.
  1. +6 −0 lib/matplotlib/backend_bases.py
  2. +16 −2 lib/matplotlib/figure.py
@@ -2433,6 +2433,12 @@ def __init__(self, canvas, num):
"""
+ def show(self):
+ """
+ For GUI backends, show the figure window and redraw.
+ """
+ pass
+
def destroy(self):
pass
View
@@ -338,6 +338,20 @@ def _setup_canvas(self):
backend_mod = mbackends.pylab_setup()[0]
return backend_mod.FigureCanvas(self)
+ def show(self):
+ """
+ If using a GUI backend, display the figure window.
+
+ 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")
+
def _get_axes(self):
return self._axstack.as_list()
@@ -1188,10 +1202,10 @@ def __getstate__(self):
# and re-attached to another.
for attr_to_pop in ('_axobservers', 'show', 'canvas', '_cachedRenderer') :
state.pop(attr_to_pop, None)
-
+
# add version information to the state
state['__mpl_version__'] = _mpl_version
-
+
# check to see if the figure has a manager and whether it is registered
# with pyplot
if getattr(self.canvas, 'manager', None) is not None:

0 comments on commit faafa59

Please sign in to comment.