@@ -430,25 +430,18 @@ def show(self, warn=True):
430430 If ``True`` and we are not running headless (i.e. on Linux with an
431431 unset DISPLAY), issue warning when called on a non-GUI backend.
432432 """
433+ if self .canvas .manager is None :
434+ raise AttributeError (
435+ "Figure.show works only for figures managed by pyplot, "
436+ "normally created by pyplot.figure()" )
433437 try :
434- manager = getattr (self .canvas , 'manager' )
435- except AttributeError as err :
436- raise AttributeError ("%s\n "
437- "Figure.show works only "
438- "for figures managed by pyplot, normally "
439- "created by pyplot.figure()." % err )
440-
441- if manager is not None :
442- try :
443- manager .show ()
444- return
445- except NonGuiException :
446- pass
447- if (backends ._get_running_interactive_framework () != "headless"
448- and warn ):
449- cbook ._warn_external ('Matplotlib is currently using %s, which is '
450- 'a non-GUI backend, so cannot show the '
451- 'figure.' % get_backend ())
438+ self .canvas .manager .show ()
439+ except NonGuiException :
440+ if (backends ._get_running_interactive_framework () != "headless"
441+ and warn ):
442+ cbook ._warn_external (
443+ f"Matplotlib is currently using { get_backend ()} , which is "
444+ f"a non-GUI backend, so cannot show the figure." )
452445
453446 def _get_axes (self ):
454447 return self ._axstack .as_list ()
0 commit comments