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

Skip to content

Commit ce93d47

Browse files
committed
Speedups in colors.py, bugfix in axes.py 2-D plot support
svn path=/trunk/matplotlib/; revision=2923
1 parent 27cf612 commit ce93d47

4 files changed

Lines changed: 24 additions & 17 deletions

File tree

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2006-12-13 Replaced calls to where() in colors.py with much faster
2+
clip() and putmask() calls; removed inappropriate
3+
uses of getmaskorNone (which should be needed only
4+
very rarely); all in response to profiling by
5+
David Cournapeau. Also fixed bugs in my 2-D
6+
array support from 12-09. - EF
7+
18
2006-12-09 Replaced spy and spy2 with the new spy that combines
29
marker and image capabilities - EF
310

examples/image_masked.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,3 @@
3838
title('Green=low, Red=high, Blue=bad')
3939
colorbar(im, extend='both', shrink=0.8)
4040
show()
41-

lib/matplotlib/axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def _plot_2_args(self, tup2, **kwargs):
292292
elif self.command == 'fill':
293293
ret = []
294294
for j in range(y.shape[1]):
295-
seg = Polygon( zip(x,y), fill=True, )
295+
seg = Polygon( zip(x[:,j],y[:,j]), fill=True, )
296296
self.set_patchprops(seg, **kwargs)
297297
ret.append(seg)
298298
return ret
@@ -317,7 +317,7 @@ def _plot_3_args(self, tup3, **kwargs):
317317
facecolor = tup3[2]
318318
ret = []
319319
for j in range(y.shape[1]):
320-
seg = Polygon(zip(x[:j],y[:,j]),
320+
seg = Polygon(zip(x[:,j],y[:,j]),
321321
facecolor = facecolor,
322322
fill=True,
323323
)

lib/matplotlib/colors.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
"""
3131
import re
3232

33-
from numerix import array, arange, take, put, Float, Int, where, \
33+
from numerix import array, arange, take, put, Float, Int, putmask, \
3434
zeros, asarray, sort, searchsorted, sometrue, ravel, divide,\
35-
ones, typecode, typecodes, alltrue
35+
ones, typecode, typecodes, alltrue, clip
3636
from numerix.mlab import amin, amax
3737
import numerix.ma as ma
3838
import numerix as nx
@@ -536,8 +536,9 @@ def makeMappingArray(N, data):
536536
lut[0] = y1[0]
537537
lut[-1] = y0[-1]
538538
# ensure that the lut is confined to values between 0 and 1 by clipping it
539-
lut = where(lut > 1., 1., lut)
540-
lut = where(lut < 0., 0., lut)
539+
clip(lut, 0.0, 1.0)
540+
#lut = where(lut > 1., 1., lut)
541+
#lut = where(lut < 0., 0., lut)
541542
return lut
542543

543544

@@ -588,16 +589,16 @@ def __call__(self, X, alpha=1.0):
588589
vtype = 'array'
589590
xma = ma.asarray(X)
590591
xa = xma.filled(0)
591-
mask_bad = ma.getmaskorNone(xma)
592+
mask_bad = ma.getmask(xma)
592593
if typecode(xa) in typecodes['Float']:
593-
xa = where(xa == 1.0, 0.9999999, xa) # Tweak so 1.0 is in range.
594+
putmask(xa, xa==1.0, 0.9999999) #Treat 1.0 as slightly less than 1.
594595
xa = (xa * self.N).astype(Int)
595-
mask_under = xa < 0
596-
mask_over = xa > self.N-1
597-
xa = where(mask_under, self._i_under, xa)
598-
xa = where(mask_over, self._i_over, xa)
599-
if mask_bad is not None: # and sometrue(mask_bad):
600-
xa = where(mask_bad, self._i_bad, xa)
596+
# Set the over-range indices before the under-range;
597+
# otherwise the under-range values get converted to over-range.
598+
putmask(xa, xa>self.N-1, self._i_over)
599+
putmask(xa, xa<0, self._i_under)
600+
if mask_bad is not None and mask_bad.shape == xa.shape:
601+
putmask(xa, mask_bad, self._i_bad)
601602
rgba = take(self._lut, xa)
602603
if vtype == 'scalar':
603604
rgba = tuple(rgba[0,:])
@@ -752,7 +753,7 @@ def __call__(self, value, clip=None):
752753
return 0.*value
753754
else:
754755
if clip:
755-
mask = ma.getmaskorNone(val)
756+
mask = ma.getmask(val)
756757
val = ma.array(nx.clip(val.filled(vmax), vmin, vmax),
757758
mask=mask)
758759
result = (val-vmin)/float(vmax-vmin)
@@ -804,7 +805,7 @@ def __call__(self, value, clip=None):
804805
return 0.*value
805806
else:
806807
if clip:
807-
mask = ma.getmaskorNone(val)
808+
mask = ma.getmask(val)
808809
val = ma.array(nx.clip(val.filled(vmax), vmin, vmax),
809810
mask=mask)
810811
result = (ma.log(val)-nx.log(vmin))/(nx.log(vmax)-nx.log(vmin))

0 commit comments

Comments
 (0)