Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e71c34

Browse files
committed
Better version of 'show' warning that only emits when show() is run directly from the python or ipython console.
svn path=/trunk/matplotlib/; revision=6175
1 parent 1c521fa commit 2e71c34

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

lib/matplotlib/backends/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import matplotlib
3+
import inspect
34
import warnings
45

56
# ipython relies on interactive_bk being defined here
@@ -30,11 +31,14 @@ def pylab_setup():
3031
# for "show" or "draw_if_interactive", so if they are not defined
3132
# by the backend, just do nothing
3233
def do_nothing_show(*args, **kwargs):
33-
warnings.warn("""
34+
frame = inspect.currentframe()
35+
fname = inspect.getframeinfo(frame.f_back)[0]
36+
if fname in ('<stdin>', '<ipython console>'):
37+
warnings.warn("""
3438
Your currently selected backend, '%s' does not support show().
3539
Please select a GUI backend in your matplotlibrc file ('%s')
3640
or with matplotlib.use()""" %
37-
(backend, matplotlib.matplotlib_fname()))
41+
(backend, matplotlib.matplotlib_fname()))
3842
def do_nothing(*args, **kwargs): pass
3943
backend_version = getattr(backend_mod,'backend_version', 'unknown')
4044
show = getattr(backend_mod, 'show', do_nothing_show)

0 commit comments

Comments
 (0)