Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32dc947

Browse files
committed
Merge pull request #1220 from efiring/clarify_figure_show
Figure.show: clarify docstring and error message
2 parents 820985a + 930b262 commit 32dc947

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/matplotlib/figure.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,23 @@ def _setup_canvas(self):
340340

341341
def show(self, warn=True):
342342
"""
343-
If using a GUI backend, display the figure window.
343+
If using a GUI backend with pyplot, display the figure window.
344+
345+
If the figure was not created using
346+
:func:`~matplotlib.pyplot.figure`, it will lack a
347+
:class:`~matplotlib.backend_bases.FigureManagerBase`, and
348+
will raise an AttributeError.
344349
345350
For non-GUI backends, this does nothing, in which case
346-
a warning will be issued if *warn* is True.
351+
a warning will be issued if *warn* is True (default).
347352
"""
348-
manager = getattr(self.canvas, 'manager')
353+
try:
354+
manager = getattr(self.canvas, 'manager')
355+
except AttributeError as err:
356+
raise AttributeError("%s\n Figure.show works only "
357+
"for figures managed by pyplot,\n normally "
358+
"created by pyplot.figure()." % err)
359+
349360
if manager is not None:
350361
try:
351362
manager.show()

0 commit comments

Comments
 (0)