Skip to content

Commit fc6d355

Browse files
committed
LogNorm: speed-up by dealing with mask explicitly
svn path=/trunk/matplotlib/; revision=8969
1 parent d47f836 commit fc6d355

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/matplotlib/colors.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,17 @@ def __call__(self, value, clip=None):
921921
mask=mask)
922922
#result = (ma.log(result)-np.log(vmin))/(np.log(vmax)-np.log(vmin))
923923
# in-place equivalent of above can be much faster
924-
np.ma.log(result, result)
925-
result -= np.log(vmin)
926-
result /= (np.log(vmax) - np.log(vmin))
924+
resdat = result.data
925+
mask = result.mask
926+
if mask is np.ma.nomask:
927+
mask = (resdat <= 0)
928+
else:
929+
mask |= resdat <= 0
930+
np.putmask(resdat, mask, 1)
931+
np.log(resdat, resdat)
932+
resdat -= np.log(vmin)
933+
resdat /= (np.log(vmax) - np.log(vmin))
934+
result = np.ma.array(resdat, mask=mask, copy=False)
927935
if is_scalar:
928936
result = result[0]
929937
return result

0 commit comments

Comments
 (0)