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

Skip to content

Commit 1111f3d

Browse files
committed
Merge commit '497681c2' into symlog_bugs
2 parents 012747b + 497681c commit 1111f3d

File tree

10 files changed

+3001
-2144
lines changed

10 files changed

+3001
-2144
lines changed

doc/users/whats_new.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ Other improvements
181181
* :meth:`~matplotlib.pyplot.scatter` now accepts empty inputs.
182182

183183
* The behavior for 'symlog' scale has been fixed, but this may result
184-
in some minor changes to existing plots.
184+
in some minor changes to existing plots. This work was refined by
185+
ssyr.
185186

186187
* Peter Butterworth added named figure support to
187188
:func:`~matplotlib.pyplot.figure`.

examples/pylab_examples/symlog_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
subplot(313)
2222
plot(x, np.sin(x / 3.0))
2323
xscale('symlog')
24-
yscale('symlog')
24+
yscale('symlog', linthreshy=0.015)
2525
grid(True)
2626
ylabel('symlog both')
2727

lib/matplotlib/scale.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -312,58 +312,56 @@ class SymmetricalLogScale(ScaleBase):
312312
name = 'symlog'
313313

314314
class SymmetricalLogTransform(Transform):
315+
input_dims = 1
316+
output_dims = 1
317+
is_separable = True
318+
319+
def __init__(self, base, linthresh):
320+
Transform.__init__(self)
321+
self.base = base
322+
self.linthresh = linthresh
323+
self._log_base = np.log(base)
324+
self._linadjust = (np.log(linthresh) / self._log_base) / linthresh
325+
326+
def transform(self, a):
327+
a = np.asarray(a)
328+
sign = np.sign(a)
329+
masked = ma.masked_inside(a, -self.linthresh, self.linthresh, copy=False)
330+
log = sign * self.linthresh * (1 + ma.log(np.abs(masked) / self.linthresh))
331+
if masked.mask.any():
332+
return np.asarray(ma.where(masked.mask,
333+
a,
334+
log))
335+
else:
336+
return np.asarray(log)
337+
338+
def inverted(self):
339+
return SymmetricalLogScale.InvertedSymmetricalLogTransform(self.base, self.linthresh)
340+
341+
class InvertedSymmetricalLogTransform(Transform):
315342
input_dims = 1
316343
output_dims = 1
317344
is_separable = True
318345

319346
def __init__(self, base, linthresh):
320347
Transform.__init__(self)
321348
self.base = base
322-
self.linthresh = abs(linthresh)
349+
self.linthresh = linthresh
323350
self._log_base = np.log(base)
324-
logb_linthresh = np.log(linthresh) / self._log_base
325-
self._linadjust = 1.0 - logb_linthresh
326-
self._linscale = 1.0 / linthresh
351+
self._log_linthresh = np.log(linthresh) / self._log_base
352+
self._linadjust = linthresh / (np.log(linthresh) / self._log_base)
327353

328354
def transform(self, a):
329355
a = np.asarray(a)
330356
sign = np.sign(a)
331357
masked = ma.masked_inside(a, -self.linthresh, self.linthresh, copy=False)
358+
exp = sign * self.linthresh * ma.exp(sign * masked / self.linthresh - 1)
332359
if masked.mask.any():
333-
log = sign * (ma.log(np.abs(masked)) / self._log_base + self._linadjust)
334-
return np.asarray(ma.where(masked.mask, a * self._linscale, log))
360+
return np.asarray(ma.where(masked.mask,
361+
a,
362+
exp))
335363
else:
336-
return sign * (np.log(np.abs(a)) / self._log_base + self._linadjust)
337-
338-
def inverted(self):
339-
return SymmetricalLogScale.InvertedSymmetricalLogTransform(
340-
self.base, self.linthresh)
341-
342-
class InvertedSymmetricalLogTransform(Transform):
343-
input_dims = 1
344-
output_dims = 1
345-
is_separable = True
346-
347-
def __init__(self, base, linthresh):
348-
Transform.__init__(self)
349-
self.base = base
350-
self.linthresh = linthresh
351-
log_base = np.log(base)
352-
logb_linthresh = np.log(linthresh) / log_base
353-
self._linadjust = 1.0 - logb_linthresh
354-
355-
def transform(self, a):
356-
a = np.asarray(a)
357-
sign = np.sign(a)
358-
masked = ma.masked_inside(a, -1.0, 1.0, copy=False)
359-
result = np.where((a >= -1.0) & (a <= 1.0),
360-
a * self.linthresh,
361-
sign * np.power(self.base, np.abs(a - sign * self._linadjust)))
362-
return result
363-
364-
def inverted(self):
365-
return SymmetricalLogScale.SymmetricalLogTransform(
366-
self.base, self.linthresh)
364+
return np.asarray(exp)
367365

368366
def __init__(self, axis, **kwargs):
369367
"""
Binary file not shown.
Loading

0 commit comments

Comments
 (0)