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,23 +29,23 @@ 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
+ # validates, to match all_backends
44
+ name = matplotlib . get_backend ()
45
+ if name .startswith ('module://' ):
46
+ backend_name = name [9 :]
44
47
else :
45
- backend_name = 'backend_' + backend
48
+ backend_name = 'backend_' + name
46
49
backend_name = backend_name .lower () # until we banish mixed case
47
50
backend_name = 'matplotlib.backends.%s' % backend_name .lower ()
48
51
@@ -65,20 +68,23 @@ def do_nothing_show(*args, **kwargs):
65
68
Your currently selected backend, '%s' does not support show().
66
69
Please select a GUI backend in your matplotlibrc file ('%s')
67
70
or with matplotlib.use()""" %
68
- (backend , matplotlib .matplotlib_fname ()))
71
+ (name , matplotlib .matplotlib_fname ()))
69
72
70
73
def do_nothing (* args , ** kwargs ):
71
74
pass
72
75
73
- backend_version = getattr (backend_mod , 'backend_version' ,
74
- 'unknown' )
76
+ backend_version = getattr (backend_mod , 'backend_version' , 'unknown' )
75
77
76
78
show = getattr (backend_mod , 'show' , do_nothing_show )
77
79
78
80
draw_if_interactive = getattr (backend_mod , 'draw_if_interactive' ,
79
81
do_nothing )
80
82
81
83
matplotlib .verbose .report ('backend %s version %s' %
82
- (backend , backend_version ))
84
+ (name , backend_version ))
83
85
86
+ # need to keep a global reference to the backend for compatibility
87
+ # reasons. See https://github.com/matplotlib/matplotlib/issues/6092
88
+ global backend
89
+ backend = name
84
90
return backend_mod , new_figure_manager , draw_if_interactive , show
0 commit comments