Skip to content

Commit 397bfc7

Browse files
committed
MNT: Bring back the module level 'backend'
The removal of the module level 'backend' broke ipython's pylab code. This is the first attempt to bring it back.
1 parent 3ba9279 commit 397bfc7

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

lib/matplotlib/backends/__init__.py

Lines changed: 20 additions & 18 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,30 +29,31 @@ 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+
# 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:]
4449
else:
45-
backend_name = 'backend_' + backend
50+
backend_name = 'backend_' + name
4651
backend_name = backend_name.lower() # until we banish mixed case
4752
backend_name = 'matplotlib.backends.%s' % backend_name.lower()
4853

4954
# the last argument is specifies whether to use absolute or relative
5055
# 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)
5357

5458
# Things we pull in from all backends
5559
new_figure_manager = backend_mod.new_figure_manager
@@ -65,20 +69,18 @@ def do_nothing_show(*args, **kwargs):
6569
Your currently selected backend, '%s' does not support show().
6670
Please select a GUI backend in your matplotlibrc file ('%s')
6771
or with matplotlib.use()""" %
68-
(backend, matplotlib.matplotlib_fname()))
72+
(name, matplotlib.matplotlib_fname()))
6973

7074
def do_nothing(*args, **kwargs):
7175
pass
7276

73-
backend_version = getattr(backend_mod, 'backend_version',
74-
'unknown')
77+
backend_version = getattr(backend_mod, 'backend_version', 'unknown')
7578

7679
show = getattr(backend_mod, 'show', do_nothing_show)
7780

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)
8082

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

8486
return backend_mod, new_figure_manager, draw_if_interactive, show

0 commit comments

Comments
 (0)