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

Skip to content

Commit 930b262

Browse files
committed
Figure.show: clarify docstring and error message
Figure.show is only for use with the pyplot figure management framework. The error of trying to use it in a pure OO context, with a directly-instantiated Figure instance, now generates an error message explaining this.
1 parent 820985a commit 930b262

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)