From: <md...@us...> - 2010-10-13 18:02:05
|
Revision: 8752 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8752&view=rev Author: mdboom Date: 2010-10-13 18:01:59 +0000 (Wed, 13 Oct 2010) Log Message: ----------- Fix is_decade() Modified Paths: -------------- branches/v1_0_maint/lib/matplotlib/ticker.py Modified: branches/v1_0_maint/lib/matplotlib/ticker.py =================================================================== --- branches/v1_0_maint/lib/matplotlib/ticker.py 2010-10-13 15:45:14 UTC (rev 8751) +++ branches/v1_0_maint/lib/matplotlib/ticker.py 2010-10-13 18:01:59 UTC (rev 8752) @@ -546,7 +546,7 @@ sign = np.sign(x) # only label the decades fx = math.log(abs(x))/math.log(b) - isDecade = self.is_decade(fx) + isDecade = is_decade(fx) if not isDecade and self.labelOnlyBase: s = '' elif x>10000: s= '%1.0e'%x elif x<1: s = '%1.0e'%x @@ -567,15 +567,6 @@ 'return a short formatted string representation of a number' return '%-12g'%value - def is_decade(self, x): - n = self.nearest_long(x) - return abs(x-n)<1e-10 - - def nearest_long(self, x): - if x == 0: return 0L - elif x > 0: return long(x+0.5) - else: return long(x-0.5) - def pprint_val(self, x, d): #if the number is not too big and it's an int, format it as an #int @@ -617,7 +608,7 @@ sign = np.sign(x) # only label the decades fx = math.log(abs(x))/math.log(b) - isDecade = self.is_decade(fx) + isDecade = is_decade(fx) if not isDecade and self.labelOnlyBase: s = '' #if 0: pass elif fx>10000: s= '%1.0e'%fx @@ -644,7 +635,7 @@ return '$0$' sign = np.sign(x) fx = math.log(abs(x))/math.log(b) - isDecade = self.is_decade(fx) + isDecade = is_decade(fx) usetex = rcParams['text.usetex'] @@ -661,10 +652,10 @@ s = '$\mathdefault{%s%d^{%.2f}}$'% (sign_string, b, fx) else: if usetex: - s = r'$%s%d^{%d}$'% (sign_string, b, self.nearest_long(fx)) + s = r'$%s%d^{%d}$'% (sign_string, b, nearest_long(fx)) else: s = r'$\mathdefault{%s%d^{%d}}$'% (sign_string, b, - self.nearest_long(fx)) + nearest_long(fx)) return s @@ -1190,11 +1181,16 @@ lx = math.ceil(math.log(x)/math.log(base)) return base**lx -def is_decade(x,base=10): +def nearest_long(x): + if x == 0: return 0L + elif x > 0: return long(x+0.5) + else: return long(x-0.5) + +def is_decade(x, base=10): if x == 0.0: return True lx = math.log(x)/math.log(base) - return lx==int(lx) + return abs(lx - nearest_long(lx)) < 1e-10 class LogLocator(Locator): """ @@ -1212,7 +1208,7 @@ def base(self,base): """ - set the base of the log scaling (major tick every base**i, i interger) + set the base of the log scaling (major tick every base**i, i integer) """ self._base=base+0.0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |