Skip to content

Commit 2b4e698

Browse files
committed
Merge pull request #6013 from tacaswell/mnt_cleanup_pylab_setup
Mnt cleanup pylab setup
2 parents f555fec + b3c4e0a commit 2b4e698

File tree

3 files changed

+44
-24
lines changed

3 files changed

+44
-24
lines changed

lib/matplotlib/backends/__init__.py

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,49 @@
77
import inspect
88
import warnings
99

10-
# ipython relies on interactive_bk being defined here
11-
from matplotlib.rcsetup import interactive_bk
1210

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
1513
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.
1716
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+
'''
2038
# Import the requested backend into a generic module object
39+
if backend is None:
40+
backend = matplotlib.get_backend() # validates, to match all_backends
2141

2242
if backend.startswith('module://'):
2343
backend_name = backend[9:]
2444
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()
2848

2949
# the last argument is specifies whether to use absolute or relative
3050
# 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)
3353

3454
# Things we pull in from all backends
3555
new_figure_manager = backend_mod.new_figure_manager
@@ -46,17 +66,19 @@ def do_nothing_show(*args, **kwargs):
4666
Please select a GUI backend in your matplotlibrc file ('%s')
4767
or with matplotlib.use()""" %
4868
(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+
5176
show = getattr(backend_mod, 'show', do_nothing_show)
52-
draw_if_interactive = getattr(backend_mod, 'draw_if_interactive', do_nothing)
5377

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

60-
matplotlib.verbose.report('backend %s version %s' % (backend,backend_version))
81+
matplotlib.verbose.report('backend %s version %s' %
82+
(backend, backend_version))
6183

6284
return backend_mod, new_figure_manager, draw_if_interactive, show

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
Locator, IndexLocator, FixedLocator, NullLocator,\
6666
LinearLocator, LogLocator, AutoLocator, MultipleLocator,\
6767
MaxNLocator
68-
68+
from matplotlib.backends import pylab_setup
6969

7070
## Backend detection ##
7171
def _backend_selection():
@@ -110,7 +110,6 @@ def _backend_selection():
110110

111111
## Global ##
112112

113-
from matplotlib.backends import pylab_setup
114113
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
115114

116115
_IP_REGISTERED = None

lib/matplotlib/tests/test_coding_standards.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ def test_pep8_conformance_installed_files():
216216
'tests/test_tightlayout.py',
217217
'tests/test_triangulation.py',
218218
'compat/subprocess.py',
219-
'backends/__init__.py',
220219
'backends/backend_agg.py',
221220
'backends/backend_cairo.py',
222221
'backends/backend_cocoaagg.py',

0 commit comments

Comments
 (0)