8
8
import warnings
9
9
10
10
11
- def pylab_setup (backend = None ):
11
+ backend = matplotlib .get_backend ()
12
+
13
+
14
+ def pylab_setup (name = None ):
12
15
'''return new_figure_manager, draw_if_interactive and show for pyplot
13
16
14
17
This provides the backend-specific functions that are used by
15
18
pyplot to abstract away the difference between interactive backends.
16
19
17
20
Parameters
18
21
----------
19
- backend : str, optional
22
+ name : str, optional
20
23
The name of the backend to use. If `None`, falls back to
21
24
``matplotlib.get_backend()`` (which return ``rcParams['backend']``)
22
25
@@ -26,30 +29,31 @@ def pylab_setup(backend=None):
26
29
The module which contains the backend of choice
27
30
28
31
new_figure_manager : function
29
- Create a new figure manage (roughly maps to GUI window)
32
+ Create a new figure manager (roughly maps to GUI window)
30
33
31
34
draw_if_interactive : function
32
35
Redraw the current figure if pyplot is interactive
33
36
34
37
show : function
35
- Show (and possible block) any unshown figures.
38
+ Show (and possibly block) any unshown figures.
36
39
37
40
'''
38
41
# Import the requested backend into a generic module object
39
- if backend is None :
40
- backend = matplotlib .get_backend () # validates, to match all_backends
41
-
42
- if backend .startswith ('module://' ):
43
- backend_name = backend [9 :]
42
+ if name is None :
43
+ # need to keep a global reference to the backend for compatibility
44
+ # reasons. See https://github.com/matplotlib/matplotlib/issues/6092
45
+ global backend
46
+ name = backend
47
+ if name .startswith ('module://' ):
48
+ backend_name = name [9 :]
44
49
else :
45
- backend_name = 'backend_' + backend
50
+ backend_name = 'backend_' + name
46
51
backend_name = backend_name .lower () # until we banish mixed case
47
52
backend_name = 'matplotlib.backends.%s' % backend_name .lower ()
48
53
49
54
# the last argument is specifies whether to use absolute or relative
50
55
# imports. 0 means only perform absolute imports.
51
- backend_mod = __import__ (backend_name , globals (), locals (),
52
- [backend_name ], 0 )
56
+ backend_mod = __import__ (backend_name , globals (), locals (), [backend_name ], 0 )
53
57
54
58
# Things we pull in from all backends
55
59
new_figure_manager = backend_mod .new_figure_manager
@@ -65,20 +69,18 @@ def do_nothing_show(*args, **kwargs):
65
69
Your currently selected backend, '%s' does not support show().
66
70
Please select a GUI backend in your matplotlibrc file ('%s')
67
71
or with matplotlib.use()""" %
68
- (backend , matplotlib .matplotlib_fname ()))
72
+ (name , matplotlib .matplotlib_fname ()))
69
73
70
74
def do_nothing (* args , ** kwargs ):
71
75
pass
72
76
73
- backend_version = getattr (backend_mod , 'backend_version' ,
74
- 'unknown' )
77
+ backend_version = getattr (backend_mod , 'backend_version' , 'unknown' )
75
78
76
79
show = getattr (backend_mod , 'show' , do_nothing_show )
77
80
78
- draw_if_interactive = getattr (backend_mod , 'draw_if_interactive' ,
79
- do_nothing )
81
+ draw_if_interactive = getattr (backend_mod , 'draw_if_interactive' , do_nothing )
80
82
81
83
matplotlib .verbose .report ('backend %s version %s' %
82
- (backend , backend_version ))
84
+ (name , backend_version ))
83
85
84
86
return backend_mod , new_figure_manager , draw_if_interactive , show
0 commit comments