File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2563,11 +2563,15 @@ def notify_axes_change(fig):
25632563 def show (self ):
25642564 """
25652565 For GUI backends, show the figure window and redraw.
2566- For non-GUI backends, raise an exception to be caught
2567- by :meth:`~matplotlib.figure.Figure.show`, for an
2568- optional warning.
2566+ For non-GUI backends, raise an exception, unless running headless (i.e.
2567+ on Linux with an unset DISPLAY); this exception is converted to a
2568+ warning in `.Figure.show` .
25692569 """
2570- raise NonGuiException ()
2570+ # This should be overridden in GUI backends.
2571+ if mpl .backends ._get_running_interactive_framework () != "headless" :
2572+ raise NonGuiException (
2573+ f"Matplotlib is currently using { get_backend ()} , which is "
2574+ f"a non-GUI backend, so cannot show the figure." )
25712575
25722576 def destroy (self ):
25732577 pass
@@ -3360,8 +3364,10 @@ def show(cls, block=None):
33603364 if not managers :
33613365 return
33623366 for manager in managers :
3363- # Emits a warning if the backend is non-interactive.
3364- manager .canvas .figure .show ()
3367+ try :
3368+ manager .show () # Emits a warning for non-interactive backend.
3369+ except NonGuiException as exc :
3370+ cbook ._warn_external (str (exc ))
33653371 if cls .mainloop is None :
33663372 return
33673373 if block is None :
Original file line number Diff line number Diff line change @@ -436,12 +436,8 @@ def show(self, warn=True):
436436 "normally created by pyplot.figure()" )
437437 try :
438438 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." )
439+ except NonGuiException as exc :
440+ cbook ._warn_external (str (exc ))
445441
446442 def _get_axes (self ):
447443 return self ._axstack .as_list ()
You can’t perform that action at this time.
0 commit comments