8000 Add a "show" method to figures that don't have a GUI backend. Fixed … · dmcdougall/matplotlib@faafa59 · GitHub
[go: up one dir, main page]

Skip to content

Commit faafa59

Browse files
mdboomefiring
authored andcommitted
Add a "show" method to figures that don't have a GUI backend. Fixed matplotlib#835.
1 parent 0f9f85f commit faafa59

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,12 @@ def __init__(self, canvas, num):
24332433
24342434
"""
24352435

2436+
def show(self):
2437+
"""
2438+
For GUI backends, show the figure window and redraw.
2439+
"""
2440+
pass
2441+
24362442
def destroy(self):
24372443
pass
24382444

lib/matplotlib/figure.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,20 @@ def _setup_canvas(self):
338338
backend_mod = mbackends.pylab_setup()[0]
339339
return backend_mod.FigureCanvas(self)
340340

341+
def show(self):
342+
"""
343+
If using a GUI backend, display the figure window.
344+
345+
For non-GUI backends, this does nothing.
346+
"""
347+
manager = getattr(self.canvas, 'manager')
348+
if manager is not None:
349+
manager.show()
350+
import warnings
351+
warnings.warn(
352+
"matplotlib is currently using a non-GUI backend, "
353+
"so can not show the figure")
354+
341355
def _get_axes(self):
342356
return self._axstack.as_list()
343357

@@ -1188,10 +1202,10 @@ def __getstate__(self):
11881202
# and re-attached to another.
11891203
for attr_to_pop in ('_axobservers', 'show', 'canvas', '_cachedRenderer') :
11901204
state.pop(attr_to_pop, None)
1191-
1205+
11921206
# add version information to the state
11931207
state['__mpl_version__'] = _mpl_version
1194-
1208+
11951209
# check to see if the figure has a manager and whether it is registered
11961210
# with pyplot
11971211
if getattr(self.canvas, 'manager', None) is not None:

0 commit comments

Comments
 (0)
0