File tree Expand file tree Collapse file tree 2 files changed +14
-12
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +14
-12
lines changed
Original file line number Diff line number Diff line change @@ -2563,11 +2563,15 @@ def notify_axes_change(fig):
2563
2563
def show (self ):
2564
2564
"""
2565
2565
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` .
2569
2569
"""
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." )
2571
2575
2572
2576
def destroy (self ):
2573
2577
pass
@@ -3360,8 +3364,10 @@ def show(cls, block=None):
3360
3364
if not managers :
3361
3365
return
3362
3366
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 ))
3365
3371
if cls .mainloop is None :
3366
3372
return
3367
3373
if block is None :
Original file line number Diff line number Diff line change @@ -436,12 +436,8 @@ def show(self, warn=True):
436
436
"normally created by pyplot.figure()" )
437
437
try :
438
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." )
439
+ except NonGuiException as exc :
440
+ cbook ._warn_external (str (exc ))
445
441
446
442
def _get_axes (self ):
447
443
return self ._axstack .as_list ()
You can’t perform that action at this time.
0 commit comments