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

Skip to content

Commit 339c86f

Browse files
committed
Support for maskedarray alternative to ma
svn path=/trunk/matplotlib/; revision=3391
1 parent 9f35685 commit 339c86f

10 files changed

Lines changed: 53 additions & 9 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2007-06-13 Added maskedarray option to rc, numerix - EF
2+
13
2007-06-11 Python 2.5 compatibility fix for mlab.py - EF
24

35
2007-06-10 In matplotlibrc file, use 'dashed' | 'solid' instead

CODING_GUIDE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ For numpy, use:
4747
a = npy.array([1,2,3])
4848
...
4949

50+
For masked arrays, use:
51+
import matplotlib.numerix.npyma as ma
52+
53+
(This is needed to support the maskedarray module as an
54+
alternative to the original numpy ma module; eventually,
55+
the maskedarray implementation is likely to replace the
56+
ma implementation.)
57+
5058
For matplotlib main module, use:
5159

5260
import matplotlib as mpl

examples/backend_driver.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,17 @@
8888
SVG = ('tex_demo.py,'),
8989
)
9090

91-
def drive(backend, python='python'):
91+
def drive(backend, python='python', switches = []):
9292

9393
exclude = failbackend.get(backend, [])
94+
switchstring = ' '.join(switches)
9495

9596
for fname in files:
9697
if fname in exclude:
9798
print '\tSkipping %s, known to fail on backend: %s'%backend
9899
continue
99100

100-
print '\tdriving %s' % fname
101+
print '\tdriving %s %s' % (fname, switchstring)
101102
basename, ext = os.path.splitext(fname)
102103
outfile = basename + '_%s'%backend
103104
tmpfile_name = '_tmp_%s.py' % basename
@@ -123,7 +124,7 @@ def drive(backend, python='python'):
123124
tmpfile.write('savefig("%s", dpi=150)' % outfile)
124125

125126
tmpfile.close()
126-
os.system('%s %s' % (python, tmpfile_name))
127+
os.system('%s %s %s' % (python, tmpfile_name, switchstring))
127128
os.remove(tmpfile_name)
128129

129130

@@ -139,14 +140,16 @@ def drive(backend, python='python'):
139140
python = r'c:\Python24\python.exe'
140141
else:
141142
python = 'python'
143+
switches = []
142144
if sys.argv[1:]:
143145
backends = [b for b in sys.argv[1:] if b in default_backends]
144-
else:
146+
switches = [s for s in sys.argv[1:] if s.startswith('--')]
147+
if not backends:
145148
backends = default_backends
146149
for backend in backends:
147150
print 'testing %s' % backend
148151
t0 = time.time()
149-
drive(backend, python)
152+
drive(backend, python, switches)
150153
t1 = time.time()
151154
times[backend] = (t1-t0)/60.0
152155

lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ def __call__(self, s):
744744
defaultParams = {
745745
'backend' : ['WXAgg', validate_backend],
746746
'numerix' : ['numpy', validate_numerix],
747+
'maskedarray' : [False, validate_bool],
747748
'toolbar' : ['toolbar2', validate_toolbar],
748749
'datapath' : [get_data_path(), validate_path_exists],
749750
'units' : [False, validate_bool],

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
# Agg Cairo GD GDK Paint PS PDF SVG Template
2929
backend : TkAgg
3030
numerix : numpy # numpy, Numeric or numarray
31+
#maskedarray : False # True to use external maskedarray module
32+
# instead of numpy.ma; this is a temporary
33+
# setting for testing maskedarray.
3134
#interactive : False # see http://matplotlib.sourceforge.net/interactive.html
3235
#toolbar : toolbar2 # None | classic | toolbar2
3336
#timezone : UTC # a pytz timezone string, eg US/Central or Europe/Paris

lib/matplotlib/numerix/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from matplotlib import rcParams, verbose
2121

2222
which = None, None
23+
use_maskedarray = None
2324

2425
# First, see if --numarray or --Numeric was specified on the command
2526
# line:
@@ -30,15 +31,24 @@
3031
"--NumPy", "--numpy", "--NUMPY", "--Numpy",
3132
]:
3233
which = a[2:], "command line"
33-
break
34-
del a
34+
if a == "--maskedarray":
35+
use_maskedarray = True
36+
if a == "--ma":
37+
use_maskedarray = False
38+
del a
3539

3640
if which[0] is None:
3741
try: # In theory, rcParams always has *some* value for numerix.
3842
which = rcParams['numerix'], "rc"
3943
except KeyError:
4044
pass
4145

46+
if use_maskedarray is None:
47+
try:
48+
use_maskedarray = rcParams['maskedarray']
49+
except KeyError:
50+
use_maskedarray = False
51+
4252
# If all the above fail, default to Numeric. Most likely not used.
4353
if which[0] is None:
4454
which = "numeric", "defaulted"

lib/matplotlib/numerix/ma/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from matplotlib.numerix import which
1+
from matplotlib.numerix import which, use_maskedarray
22

33
if which[0] == "numarray":
44
from numarray.ma import *
@@ -9,7 +9,12 @@
99
nomask = None
1010
getmaskorNone = getmask
1111
elif which[0] == "numpy":
12-
from numpy.core.ma import *
12+
if use_maskedarray:
13+
from maskedarray import *
14+
print "using maskedarray"
15+
else:
16+
from numpy.core.ma import *
17+
#print "using ma"
1318
def getmaskorNone(obj):
1419
_msk = getmask(obj)
1520
if _msk is nomask:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from matplotlib.numerix import use_maskedarray
2+
3+
if use_maskedarray:
4+
from maskedarray import *
5+
print "using maskedarray"
6+
else:
7+
from numpy.core.ma import *
8+
#print "using ma"

matplotlibrc.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
# Agg Cairo GD GDK Paint PS PDF SVG Template
2929
backend : %(backend)s
3030
numerix : %(numerix)s # numpy, Numeric or numarray
31+
#maskedarray : False # True to use external maskedarray module
32+
# instead of numpy.ma; this is a temporary
33+
# setting for testing maskedarray.
3134
#interactive : False # see http://matplotlib.sourceforge.net/interactive.html
3235
#toolbar : toolbar2 # None | classic | toolbar2
3336
#timezone : UTC # a pytz timezone string, eg US/Central or Europe/Paris

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
'matplotlib.numerix',
131131
'matplotlib.numerix.mlab',
132132
'matplotlib.numerix.ma',
133+
'matplotlib.numerix.npyma',
133134
'matplotlib.numerix.linear_algebra',
134135
'matplotlib.numerix.random_array',
135136
'matplotlib.numerix.fft',

0 commit comments

Comments
 (0)