77import inspect
88import warnings
99
10- # ipython relies on interactive_bk being defined here
11- from matplotlib .rcsetup import interactive_bk
1210
13- __all__ = [ ' backend' , 'show' , 'draw_if_interactive' ,
14- 'new_figure_manager' , 'backend_version' ]
11+ def pylab_setup ( backend = None ):
12+ '''return new_figure_manager, draw_if_interactive and show for pyplot
1513
16- backend = matplotlib .get_backend () # validates, to match all_backends
14+ This provides the backend-specific functions that are used by
15+ pyplot to abstract away the difference between interactive backends.
1716
18- def pylab_setup ():
19- 'return new_figure_manager, draw_if_interactive and show for pylab'
17+ Parameters
18+ ----------
19+ backend : str, optional
20+ The name of the backend to use. If `None`, falls back to
21+ ``matplotlib.get_backend()`` (which return ``rcParams['backend']``)
22+
23+ Returns
24+ -------
25+ backend_mod : module
26+ The module which contains the backend of choice
27+
28+ new_figure_manager : function
29+ Create a new figure manage (roughly maps to GUI window)
30+
31+ draw_if_interactive : function
32+ Redraw the current figure if pyplot is interactive
33+
34+ show : function
35+ Show (and possible block) any unshown figures.
36+
37+ '''
2038 # Import the requested backend into a generic module object
39+ if backend is None :
40+ backend = matplotlib .get_backend () # validates, to match all_backends
2141
2242 if backend .startswith ('module://' ):
2343 backend_name = backend [9 :]
2444 else :
25- backend_name = 'backend_' + backend
26- backend_name = backend_name .lower () # until we banish mixed case
27- backend_name = 'matplotlib.backends.%s' % backend_name .lower ()
45+ backend_name = 'backend_' + backend
46+ backend_name = backend_name .lower () # until we banish mixed case
47+ backend_name = 'matplotlib.backends.%s' % backend_name .lower ()
2848
2949 # the last argument is specifies whether to use absolute or relative
3050 # imports. 0 means only perform absolute imports.
31- backend_mod = __import__ (backend_name ,
32- globals (), locals (), [backend_name ],0 )
51+ backend_mod = __import__ (backend_name , globals (), locals (),
52+ [backend_name ], 0 )
3353
3454 # Things we pull in from all backends
3555 new_figure_manager = backend_mod .new_figure_manager
@@ -46,17 +66,19 @@ def do_nothing_show(*args, **kwargs):
4666Please select a GUI backend in your matplotlibrc file ('%s')
4767or with matplotlib.use()""" %
4868 (backend , matplotlib .matplotlib_fname ()))
49- def do_nothing (* args , ** kwargs ): pass
50- backend_version = getattr (backend_mod ,'backend_version' , 'unknown' )
69+
70+ def do_nothing (* args , ** kwargs ):
71+ pass
72+
73+ backend_version = getattr (backend_mod , 'backend_version' ,
74+ 'unknown' )
75+
5176 show = getattr (backend_mod , 'show' , do_nothing_show )
52- draw_if_interactive = getattr (backend_mod , 'draw_if_interactive' , do_nothing )
5377
54- # Additional imports which only happen for certain backends. This section
55- # should probably disappear once all backends are uniform.
56- if backend .lower () in ['wx' ,'wxagg' ]:
57- Toolbar = backend_mod .Toolbar
58- __all__ .append ('Toolbar' )
78+ draw_if_interactive = getattr (backend_mod , 'draw_if_interactive' ,
79+ do_nothing )
5980
60- matplotlib .verbose .report ('backend %s version %s' % (backend ,backend_version ))
81+ matplotlib .verbose .report ('backend %s version %s' %
82+ (backend , backend_version ))
6183
6284 return backend_mod , new_figure_manager , draw_if_interactive , show
0 commit comments