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

Skip to content

Commit b218e7c

Browse files
committed
SymmetricalLogTransform and inverse return same type as input.
Their transform_non_affine methods have been updated following the strategy used in LogTransform so that they work correctly with masked arrays or plain ndarrays, but do not require any explicit np.ma functions.
1 parent d3ca16c commit b218e7c

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

lib/matplotlib/scale.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -485,18 +485,14 @@ def __init__(self, base, linthresh, linscale):
485485
self._log_base = np.log(base)
486486

487487
def transform_non_affine(self, a):
488-
sign = np.sign(a)
489-
masked = ma.masked_inside(a,
490-
-self.linthresh,
491-
self.linthresh,
492-
copy=True)
493-
log = sign * self.linthresh * (
494-
self._linscale_adj +
495-
ma.log(np.abs(masked) / self.linthresh) / self._log_base)
496-
if masked.mask.any():
497-
return ma.where(masked.mask, a * self._linscale_adj, log)
498-
else:
499-
return log
488+
abs_a = np.abs(a)
489+
with np.errstate(divide="ignore", invalid="ignore"):
490+
out = np.sign(a) * self.linthresh * (
491+
self._linscale_adj +
492+
np.log(abs_a / self.linthresh) / self._log_base)
493+
inside = abs_a <= self.linthresh
494+
out[inside] = a[inside] * self._linscale_adj
495+
return out
500496

501497
def inverted(self):
502498
return InvertedSymmetricalLogTransform(self.base, self.linthresh,
@@ -519,16 +515,13 @@ def __init__(self, base, linthresh, linscale):
519515
self._linscale_adj = (linscale / (1.0 - self.base ** -1))
520516

521517
def transform_non_affine(self, a):
522-
sign = np.sign(a)
523-
masked = ma.masked_inside(a, -self.invlinthresh,
524-
self.invlinthresh, copy=True)
525-
exp = sign * self.linthresh * (
526-
ma.power(self.base, (sign * (masked / self.linthresh))
527-
- self._linscale_adj))
528-
if masked.mask.any():
529-
return ma.where(masked.mask, a / self._linscale_adj, exp)
530-
else:
531-
return exp
518+
abs_a = np.abs(a)
519+
with np.errstate(divide="ignore", invalid="ignore"):
520+
out = np.sign(a) * self.linthresh * (
521+
np.power(self.base, abs_a / self.linthresh - self._linscale_adj))
522+
inside = abs_a <= self.invlinthresh
523+
out[inside] = a[inside] / self._linscale_adj
524+
return out
532525

533526
def inverted(self):
534527
return SymmetricalLogTransform(self.base,

0 commit comments

Comments
 (0)