Skip to content

Commit a676944

Browse files
committed
plt.show warns if a non-GUI backend is being used
1 parent 25a4bb5 commit a676944

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,28 @@ def draw_if_interactive(cls):
175175
cls.trigger_manager_draw(manager)
176176

177177
@classmethod
178-
def show(cls, block=None):
178+
def show(cls, block=None, warn=True):
179179
"""Show all figures.
180180
181181
`show` blocks by calling `mainloop` if *block* is ``True``, or if it
182182
is ``None`` and we are neither in IPython's ``%pylab`` mode, nor in
183183
`interactive` mode.
184184
"""
185-
if cls.mainloop is None:
186-
return
187185
managers = Gcf.get_all_fig_managers()
188186
if not managers:
189187
return
190188
for manager in managers:
191-
manager.show()
189+
try:
190+
manager.show()
191+
except NonGuiException:
192+
if warn:
193+
import warnings
194+
warnings.warn(
195+
"matplotlib is currently using a non-GUI backend, "
196+
"so cannot show the figure")
197+
return
198+
if cls.mainloop is None:
199+
return
192200
if block is None:
193201
# Hack: Are we in IPython's pylab mode?
194202
from matplotlib import pyplot

0 commit comments

Comments
 (0)