From 930b262712ce02862321125f3d0bab2ede6f6b92 Mon Sep 17 00:00:00 2001 From: Eric Firing Date: Sat, 8 Sep 2012 10:03:04 -1000 Subject: [PATCH] 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. --- lib/matplotlib/figure.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index eca962ba40a0..be4c5fb5aa45 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -340,12 +340,23 @@ def _setup_canvas(self): def show(self, warn=True): """ - If using a GUI backend, display the figure window. + If using a GUI backend with pyplot, display the figure window. + + If the figure was not created using + :func:`~matplotlib.pyplot.figure`, it will lack a + :class:`~matplotlib.backend_bases.FigureManagerBase`, and + will raise an AttributeError. For non-GUI backends, this does nothing, in which case - a warning will be issued if *warn* is True. + a warning will be issued if *warn* is True (default). """ - manager = getattr(self.canvas, 'manager') + try: + manager = getattr(self.canvas, 'manager') + except AttributeError as err: + raise AttributeError("%s\n Figure.show works only " + "for figures managed by pyplot,\n normally " + "created by pyplot.figure()." % err) + if manager is not None: try: manager.show()