Skip to content

Commit a2594f9

Browse files
committed
Merged revisions 8752 via svnmerge from
https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v1_0_maint ........ r8752 | mdboom | 2010-10-13 14:01:59 -0400 (Wed, 13 Oct 2010) | 2 lines Fix is_decade() ........ svn path=/trunk/matplotlib/; revision=8753
1 parent 55ea4ab commit a2594f9

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

lib/matplotlib/ticker.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ def __call__(self, x, pos=None):
545545
sign = np.sign(x)
546546
# only label the decades
547547
fx = math.log(abs(x))/math.log(b)
548-
isDecade = self.is_decade(fx)
548+
isDecade = is_decade(fx)
549549
if not isDecade and self.labelOnlyBase: s = ''
550550
elif x>10000: s= '%1.0e'%x
551551
elif x<1: s = '%1.0e'%x
@@ -566,15 +566,6 @@ def format_data_short(self,value):
566566
'return a short formatted string representation of a number'
567567
return '%-12g'%value
568568

569-
def is_decade(self, x):
570-
n = self.nearest_long(x)
571-
return abs(x-n)<1e-10
572-
573-
def nearest_long(self, x):
574-
if x == 0: return 0L
575-
elif x > 0: return long(x+0.5)
576-
else: return long(x-0.5)
577-
578569
def pprint_val(self, x, d):
579570
#if the number is not too big and it's an int, format it as an
580571
#int
@@ -616,7 +607,7 @@ def __call__(self, x, pos=None):
616607
sign = np.sign(x)
617608
# only label the decades
618609
fx = math.log(abs(x))/math.log(b)
619-
isDecade = self.is_decade(fx)
610+
isDecade = is_decade(fx)
620611
if not isDecade and self.labelOnlyBase: s = ''
621612
#if 0: pass
622613
elif fx>10000: s= '%1.0e'%fx
@@ -643,7 +634,7 @@ def __call__(self, x, pos=None):
643634
return '$0$'
644635
sign = np.sign(x)
645636
fx = math.log(abs(x))/math.log(b)
646-
isDecade = self.is_decade(fx)
637+
isDecade = is_decade(fx)
647638

648639
usetex = rcParams['text.usetex']
649640

@@ -660,10 +651,10 @@ def __call__(self, x, pos=None):
660651
s = '$\mathdefault{%s%d^{%.2f}}$'% (sign_string, b, fx)
661652
else:
662653
if usetex:
663-
s = r'$%s%d^{%d}$'% (sign_string, b, self.nearest_long(fx))
654+
s = r'$%s%d^{%d}$'% (sign_string, b, nearest_long(fx))
664655
else:
665656
s = r'$\mathdefault{%s%d^{%d}}$'% (sign_string, b,
666-
self.nearest_long(fx))
657+
nearest_long(fx))
667658

668659
return s
669660

@@ -1189,11 +1180,16 @@ def decade_up(x, base=10):
11891180
lx = np.ceil(np.log(x)/np.log(base))
11901181
return base**lx
11911182

1192-
def is_decade(x,base=10):
1183+
def nearest_long(x):
1184+
if x == 0: return 0L
1185+
elif x > 0: return long(x+0.5)
1186+
else: return long(x-0.5)
1187+
1188+
def is_decade(x, base=10):
11931189
if x == 0.0:
11941190
return True
11951191
lx = np.log(x)/np.log(base)
1196-
return lx==int(lx)
1192+
return abs(lx - nearest_long(lx)) < 1e-10
11971193

11981194
class LogLocator(Locator):
11991195
"""
@@ -1211,7 +1207,7 @@ def __init__(self, base=10.0, subs=[1.0], numdecs=4):
12111207

12121208
def base(self,base):
12131209
"""
1214-
set the base of the log scaling (major tick every base**i, i interger)
1210+
set the base of the log scaling (major tick every base**i, i integer)
12151211
"""
12161212
self._base=base+0.0
12171213

0 commit comments

Comments
 (0)