8000 Merge pull request #6095 from ericdill/module-level-backend · matplotlib/matplotlib@0d1422b · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d1422b

Browse files
committed
Merge pull request #6095 from ericdill/module-level-backend
Bring back the module level 'backend'
2 parents 6ea5e35 + 5a99151 commit 0d1422b

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

lib/matplotlib/backends/__init__.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88
import warnings
99

1010

11-
def pylab_setup(backend=None):
11+
backend = matplotlib.get_backend()
12+
13+
14+
def pylab_setup(name=None):
1215
'''return new_figure_manager, draw_if_interactive and show for pyplot
1316
1417
This provides the backend-specific functions that are used by
1518
pyplot to abstract away the difference between interactive backends.
1619
1720
Parameters
1821
----------
19-
backend : str, optional
22+
name : str, optional
2023
The name of the backend to use. If `None`, falls back to
2124
``matplotlib.get_backend()`` (which return ``rcParams['backend']``)
2225
@@ -26,23 +29,23 @@ def pylab_setup(backend=None):
2629
The module which contains the backend of choice
2730
2831
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)
3033
3134
draw_if_interactive : function
3235
Redraw the current figure if pyplot is interactive
3336
3437
show : function
35-
Show (and possible block) any unshown figures.
38+
Show (and possibly block) any unshown figures.
3639
3740
'''
3841
# 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:]
4447
else:
45-
backend_name = 'backend_' + backend
48+
backend_name = 'backend_' + name
4649
backend_name = backend_name.lower() # until we banish mixed case
4750
backend_name = 'matplotlib.backends.%s' % backend_name.lower()
4851

@@ -65,20 +68,23 @@ def do_nothing_show(*args, **kwargs):
6568
Your currently selected backend, '%s' does not support show().
6669
Please select a GUI backend in your matplotlibrc file ('%s')
6770
or with matplotlib.use()""" %
68-
(backend, matplotlib.matplotlib_fname()))
71+
(name, matplotlib.matplotlib_fname()))
6972

7073
def do_nothing(*args, **kwargs):
7174
pass
7275

73-
backend_version = getattr(backend_mod, 'backend_version',
74-
'unknown')
76+
backend_version = getattr(backend_mod, 'backend_version', 'unknown')
7577

7678
show = getattr(backend_mod, 'show', do_nothing_show)
7779

7880
draw_if_interactive = getattr(backend_mod, 'draw_if_interactive',
7981
do_nothing)
8082

8183
matplotlib.verbose.report('backend %s version %s' %
82-
(backend, backend_version))
84+
(name, backend_version))
8385

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
8490
return backend_mod, new_figure_manager, draw_if_interactive, show

0 commit comments

Comments
 (0)
0