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

Skip to content

Commit 2913067

Browse files
committed
fixed a formatting bug in ticker.ScalarFormatter (10^0 was rendered as
10 in some cases) svn path=/trunk/matplotlib/; revision=3539
1 parent 5576af5 commit 2913067

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2007-07-16 fixed a formatting bug in ticker.ScalarFormatter's scientific
2+
notation (10^0 was being rendered as 10 in some cases) - DSD
3+
14
2007-07-13 Add MPL_isfinite64() and MPL_isinf64() for testing
25
doubles in (the now misnamed) MPL_isnan.h. - ADS
36

lib/matplotlib/ticker.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -402,27 +402,26 @@ def pprint_val(self, x):
402402
if absolute(xp) < 1e-8: xp = 0
403403
return self.format % xp
404404

405-
def _formatSciNotation(self,s, mathtext=False):
405+
def _formatSciNotation(self, s, mathtext=False):
406406
# transform 1e+004 into 1e4, for example
407407
tup = s.split('e')
408408
try:
409-
mantissa = tup[0].rstrip('0').rstrip('.')
409+
significand = tup[0].rstrip('0').rstrip('.')
410410
sign = tup[1][0].replace('+', '')
411411
exponent = tup[1][1:].lstrip('0')
412412
if mathtext:
413-
if self._usetex:
414-
if mantissa=='1':
415-
return r'10^{%s%s}'%(sign, exponent)
416-
else:
417-
return r'%s{\times}10^{%s%s}'%(mantissa, sign, exponent)
413+
if significand == '1':
414+
# reformat 1x10^y as 10^y
415+
significand = ''
416+
if exponent:
417+
exponent = '10^{%s%s}'%(sign, exponent)
418+
if significand and exponent:
419+
return r'%s{\times}%s'%(significand, exponent)
418420
else:
419-
if mantissa=='1':
420-
return r'10^{%s%s}'%(sign, exponent)
421-
else:
422-
return r'%s{\times}10^{%s%s}'%(mantissa, sign, exponent)
421+
return r'%s%s'%(significand, exponent)
423422
else:
424-
return ('%se%s%s' %(mantissa, sign, exponent)).rstrip('e')
425-
except IndexError,msg:
423+
return ('%se%s%s' %(significand, sign, exponent)).rstrip('e')
424+
except IndexError, msg:
426425
return s
427426

428427

0 commit comments

Comments
 (0)