 # suggestion for tickmark labels

I was thinking about the way the labels are formatted. Some of the numbers I work with are large(10^10) and small (10^-10), and the formatting wasnt quite right. I am running the following as a test:

mport matplotlib
from matplotlib.matlab import *
from numarray import array

a=array(range(10))*1e6+1e7
b = array(range(10))*1e-5+1e-4
plot(a,b)

in ticker.py, in ScalarFormatter, what is the purpose of this routine?

# if the value is just a fraction off an int, use the int
if abs(x-long(x))<0.0001*d:
if x<=10000: return '%d' % long(x + 0.5)
else: return '%1.0e'%long(x)

If commented out, the labels are formatted appropriately as exponentials, otherwise, the level of precision can often not be useful. Also, in the exponential formatting block, might this
if d < 1e-3: fmt = '%1.3f'
if d < 1e-2: fmt = '%1.3e'

One final suggestion, for formatting the exponential component:

m = self._zerorgx.match(s)
if m:
s = m.group(1)
if m.group(2) is not None:
## s += m.group(2)
s += m.group(2)[:2]+str(int(m.group(2)[2:])) ## my hack to make 3e003 look like 3e3. (Whats the "right way"?)
s = s.replace('+', '')
return s

Darren

Darren Dale wrote:

I was thinking about the way the labels are formatted. Some of the numbers I work with are large(10^10) and small (10^-10), and the formatting wasnt quite right. I am running the following as a test:

mport matplotlib
from matplotlib.matlab import *
from numarray import array

a=array(range(10))*1e6+1e7
b = array(range(10))*1e-5+1e-4
plot(a,b)

in ticker.py, in ScalarFormatter, what is the purpose of this routine?

# if the value is just a fraction off an int, use the int
if abs(x-long(x))<0.0001*d:
if x<=10000: return '%d' % long(x + 0.5)
else: return '%1.0e'%long(x)

If commented out, the labels are formatted appropriately as exponentials, otherwise, the level of precision can often not be useful. Also, in the exponential formatting block, might this
if d < 1e-3: fmt = '%1.3f'
if d < 1e-2: fmt = '%1.3e'

One final suggestion, for formatting the exponential component:

m = self._zerorgx.match(s)
if m:
s = m.group(1)
if m.group(2) is not None:
## s += m.group(2)
s += m.group(2)[:2]+str(int(m.group(2)[2:])) ## my hack to make 3e003 look like 3e3. (Whats the "right way"?)
s = s.replace('+', '')
return s

Darren

This patch has been committed, so exponential values should format correctly.

-- Paul

···

--
Paul Barrett, PhD Space Telescope Science Institute
Phone: 410-338-4475 ESS/Science Software Branch
FAX: 410-338-4767 Baltimore, MD 21218