7
7
import inspect
8
8
import warnings
9
9
10
- # ipython relies on interactive_bk being defined here
11
- from matplotlib .rcsetup import interactive_bk
12
10
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
15
13
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.
17
16
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
+ '''
20
38
# Import the requested backend into a generic module object
39
+ if backend is None :
40
+ backend = matplotlib .get_backend () # validates, to match all_backends
21
41
22
42
if backend .startswith ('module://' ):
23
43
backend_name = backend [9 :]
24
44
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 ()
28
48
29
49
# the last argument is specifies whether to use absolute or relative
30
50
# 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 )
33
53
34
54
# Things we pull in from all backends
35
55
new_figure_manager = backend_mod .new_figure_manager
@@ -46,17 +66,19 @@ def do_nothing_show(*args, **kwargs):
46
66
Please select a GUI backend in your matplotlibrc file ('%s')
47
67
or with matplotlib.use()""" %
48
68
(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
+
51
76
show = getattr (backend_mod , 'show' , do_nothing_show )
52
- draw_if_interactive = getattr (backend_mod , 'draw_if_interactive' , do_nothing )
53
77
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 )
59
80
60
- matplotlib .verbose .report ('backend %s version %s' % (backend ,backend_version ))
81
+ matplotlib .verbose .report ('backend %s version %s' %
82
+ (backend , backend_version ))
61
83
62
84
return backend_mod , new_figure_manager , draw_if_interactive , show
0 commit comments