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

Skip to content

Commit 5e69d16

Browse files
committed
[3081451] symlog doesn't handle values <1.0 correctly
svn path=/trunk/matplotlib/; revision=8731
1 parent 85ebe51 commit 5e69d16

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

lib/matplotlib/scale.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from cbook import dedent
77
from ticker import NullFormatter, ScalarFormatter, LogFormatterMathtext, Formatter
88
from ticker import NullLocator, LogLocator, AutoLocator, SymmetricalLogLocator, FixedLocator
9+
from ticker import is_decade
910
from transforms import Transform, IdentityTransform
1011
from matplotlib import docstring
1112

@@ -318,19 +319,22 @@ class SymmetricalLogTransform(Transform):
318319
def __init__(self, base, linthresh):
319320
Transform.__init__(self)
320321
self.base = base
321-
self.linthresh = linthresh
322+
self.linthresh = abs(linthresh)
322323
self._log_base = np.log(base)
323-
self._linadjust = (np.log(linthresh) / self._log_base) / linthresh
324+
self._logb_linthresh = np.log(linthresh) / self._log_base
325+
self._logb_minlog = np.floor(self._logb_linthresh - 1e-10)
326+
self._linadjust = np.abs((np.log(linthresh) - self._logb_minlog) /
327+
linthresh)
324328

325329
def transform(self, a):
326330
a = np.asarray(a)
327331
sign = np.sign(a)
328332
masked = ma.masked_inside(a, -self.linthresh, self.linthresh, copy=False)
329-
log = sign * ma.log(np.abs(masked)) / self._log_base
333+
log = sign * (ma.log(np.abs(masked)) / self._log_base - self._logb_minlog)
330334
if masked.mask.any():
331335
return np.asarray(ma.where(masked.mask,
332-
a * self._linadjust,
333-
log))
336+
a * self._linadjust,
337+
log))
334338
else:
335339
return np.asarray(log)
336340

lib/matplotlib/ticker.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,20 +1180,20 @@ def decade_down(x, base=10):
11801180
'floor x to the nearest lower decade'
11811181
if x == 0.0:
11821182
return -base
1183-
lx = math.floor(math.log(x)/math.log(base))
1183+
lx = np.floor(np.log(x)/np.log(base))
11841184
return base**lx
11851185

11861186
def decade_up(x, base=10):
11871187
'ceil x to the nearest higher decade'
11881188
if x == 0.0:
11891189
return base
1190-
lx = math.ceil(math.log(x)/math.log(base))
1190+
lx = np.ceil(np.log(x)/np.log(base))
11911191
return base**lx
11921192

11931193
def is_decade(x,base=10):
11941194
if x == 0.0:
11951195
return True
1196-
lx = math.log(x)/math.log(base)
1196+
lx = np.log(x)/np.log(base)
11971197
return lx==int(lx)
11981198

11991199
class LogLocator(Locator):
@@ -1268,15 +1268,12 @@ def __call__(self):
12681268
stride += 1
12691269

12701270
decades = np.arange(math.floor(vmin),
1271-
math.ceil(vmax)+stride, stride)
1271+
math.ceil(vmax)+stride, stride)
1272+
ticklocs = self._transform.inverted().transform(decades)
12721273
if len(subs) > 1 or (len(subs == 1) and subs[0] != 1.0):
1273-
ticklocs = []
1274-
for decadeStart in b**decades:
1275-
ticklocs.extend( subs*decadeStart )
1276-
else:
1277-
ticklocs = b**decades
1274+
ticklocs = np.ravel(np.outer(subs, ticklocs))
12781275

1279-
return self.raise_if_exceeds(np.array(ticklocs))
1276+
return self.raise_if_exceeds(np.asarray(ticklocs))
12801277

12811278
def view_limits(self, vmin, vmax):
12821279
'Try to choose the view limits intelligently'

0 commit comments

Comments
 (0)