Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2389b09

Browse files
committed
List backends only in rcsetup
svn path=/trunk/matplotlib/; revision=5419
1 parent e63a5e1 commit 2389b09

5 files changed

Lines changed: 30 additions & 26 deletions

File tree

CHANGELOG

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
2008-06-06 hist() revision, applied ideas proposed by Erik Tollerud and
1+
2008=06-07 Moved list of backends to rcsetup.py; made use of lower
2+
case for backend names consistent; use validate_backend
3+
when importing backends subpackage - EF
4+
5+
2008-06-06 hist() revision, applied ideas proposed by Erik Tollerud and
26
Olle Engdegard: make histtype='step' unfilled by default
37
and introduce histtype='stepfilled'; use default color
48
cycle; introduce reverse cumulative histogram; new align

examples/tests/backend_driver.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
from __future__ import division
1919
import os, time, sys, glob
20-
import matplotlib.backends as mplbe
2120

22-
all_backends = [b.lower() for b in mplbe.all_backends]
21+
import matplotlib.rcsetup as rcsetup
22+
23+
all_backends = list(rcsetup.all_backends) # to leave the original list alone
2324
all_backends.extend(['cairo.png', 'cairo.ps', 'cairo.pdf', 'cairo.svg'])
2425

2526
pylab_dir = os.path.join('..', 'pylab_examples')
@@ -189,7 +190,7 @@ def drive(backend, python=['python'], switches = []):
189190
line_lstrip.startswith('show')):
190191
continue
191192
tmpfile.write(line)
192-
if backend in mplbe.interactive_bk:
193+
if backend in rcsetup.interactive_bk:
193194
tmpfile.write('show()')
194195
else:
195196
tmpfile.write('savefig("%s", dpi=150)' % outfile)
@@ -205,12 +206,13 @@ def drive(backend, python=['python'], switches = []):
205206

206207
if __name__ == '__main__':
207208
times = {}
208-
default_backends = ['Agg', 'PS', 'SVG', 'PDF', 'Template']
209+
default_backends = ['agg', 'ps', 'svg', 'pdf', 'template']
209210
if len(sys.argv)==2 and sys.argv[1]=='--clean':
210211
localdirs = [d for d in glob.glob('*') if os.path.isdir(d)]
211212
all_backends_set = set(all_backends)
212213
for d in localdirs:
213-
if d.lower() not in all_backends_set: continue
214+
if d.lower() not in all_backends_set:
215+
continue
214216
print 'removing %s'%d
215217
for fname in glob.glob(os.path.join(d, '*')):
216218
os.remove(fname)

lib/matplotlib/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,14 +763,15 @@ def use(arg, warn=True):
763763
"""
764764
if 'matplotlib.backends' in sys.modules:
765765
if warn: warnings.warn(_use_error_msg)
766+
arg = arg.lower()
766767
be_parts = arg.split('.')
767768
name = validate_backend(be_parts[0])
768769
rcParams['backend'] = name
769-
if name == 'Cairo' and len(be_parts) > 1:
770+
if name == 'cairo' and len(be_parts) > 1:
770771
rcParams['cairo.format'] = validate_cairo_format(be_parts[1])
771772

772773
def get_backend():
773-
return rcParams['backend']
774+
return rcParams['backend'].lower()
774775

775776
def interactive(b):
776777
"""

lib/matplotlib/backends/__init__.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
import sys
1+
22
import matplotlib
3-
import time
3+
from matplotlib.rcsetup import interactive_bk
4+
from matplotlib.rcsetup import validate_backend
45

56
__all__ = ['backend','show','draw_if_interactive',
67
'new_figure_manager', 'backend_version']
78

8-
interactive_bk = ['GTK', 'GTKAgg', 'GTKCairo', 'FltkAgg', 'QtAgg', 'Qt4Agg',
9-
'TkAgg', 'WX', 'WXAgg', 'CocoaAgg']
10-
non_interactive_bk = ['Agg2', 'Agg', 'Cairo', 'EMF', 'GDK',
11-
'Pdf', 'PS', 'SVG', 'Template']
12-
all_backends = interactive_bk + non_interactive_bk
13-
14-
backend = matplotlib.get_backend()
15-
if backend not in all_backends:
16-
raise ValueError, 'Unrecognized backend %s' % backend
9+
backend = matplotlib.get_backend() # makes sure it is lower case
10+
validate_backend(backend)
1711

1812
def pylab_setup():
1913
'return new_figure_manager, draw_if_interactive and show for pylab'
2014
# Import the requested backend into a generic module object
2115

22-
backend_name = 'backend_'+backend.lower()
16+
backend_name = 'backend_'+backend
2317
backend_mod = __import__('matplotlib.backends.'+backend_name,
2418
globals(),locals(),[backend_name])
2519

@@ -42,7 +36,7 @@ def show(): pass
4236

4337
# Additional imports which only happen for certain backends. This section
4438
# should probably disappear once all backends are uniform.
45-
if backend in ['WX','WXAgg']:
39+
if backend in ['wx','wxagg']:
4640
Toolbar = backend_mod.Toolbar
4741
__all__.append('Toolbar')
4842

lib/matplotlib/rcsetup.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
1313
from matplotlib.colors import is_color_like
1414

15+
interactive_bk = ['GTK', 'GTKAgg', 'GTKCairo', 'FltkAgg', 'QtAgg', 'Qt4Agg',
16+
'TkAgg', 'WX', 'WXAgg', 'CocoaAgg']
17+
non_interactive_bk = ['Agg', 'Cairo', 'EMF', 'GDK',
18+
'Pdf', 'PS', 'SVG', 'Template']
19+
all_backends = interactive_bk + non_interactive_bk
20+
21+
1522
class ValidateInStrings:
1623
def __init__(self, key, valid, ignorecase=False):
1724
'valid is a list of legal strings'
@@ -80,11 +87,7 @@ def validate_fonttype(s):
8087
raise ValueError('Supported Postscript/PDF font types are %s' % fonttypes.values())
8188
return fonttype
8289

83-
validate_backend = ValidateInStrings('backend',[
84-
'Agg2', 'Agg', 'Aqt', 'Cairo', 'CocoaAgg', 'EMF', 'GD', 'GDK',
85-
'GTK', 'GTKAgg', 'GTKCairo', 'FltkAgg', 'Paint', 'Pdf', 'PS',
86-
'QtAgg', 'Qt4Agg', 'SVG', 'Template', 'TkAgg', 'WX', 'WXAgg',
87-
], ignorecase=True)
90+
validate_backend = ValidateInStrings('backend', all_backends, ignorecase=True)
8891

8992
validate_numerix = ValidateInStrings('numerix',[
9093
'Numeric','numarray','numpy',

0 commit comments

Comments
 (0)