Salut Tom,

On 25.04.07, Thomas Kornack wrote:
> I'm curious how I might implement an axis with metric prefixes such  
> as milli- micro- nano- pico- femto-? In particular, I commonly work  
> in units of Tesla over a broad range from attoTesla (aT), femtoTesla  
> (fT), picoTesla (pT) to nanoTesla (nT). I would like to make a graph  
> axis that is labeled as follows: 1 aT, 10 aT, 100 aT, 1 fT, 10 fT,  
> 100 fT, 1 pT and so on. Any suggestions? Thanks in advance!

Personally, I would prefer a dimensionless log axis with only the
exponents written at the ticks.

But, I was also curious how to implement this. The following dirty
trick overwrites the modulo function of the default strings. I took
the log.py example as a base, never mind the curved axis.

--------------------------------------------------
import math
from pyx import *
from pyx.graph import axis

text.set(mode="latex")

class mystr(str):

    prefixes = [
      (3, r"\mbox{M}"),
      (0, ""),
      (-1, r"\mbox{d}"),
      (-2, r"\mbox{c}"),
      (-3, r"\mbox{m}"),
      (-6, r"\mu{}"),
      (-9, r"\mbox{n}"),
      (-12, r"\mbox{p}"),
      (-15, r"\mbox{f}"),
      (-18, r"\mbox{a}")]

    def __mod__(self, otherstr):
        other = int(otherstr)
        for expon, pref in self.prefixes:
            if other >= expon:
                break
                o, p = other, pref
        return r"%d\,%s\mbox{T}" % (10**(other-expon), pref)

p = path.curve(0, 0, 3, 0, 1, 4, 4, 4)

mytexter = axis.texter.exponential(nomantissaexp=mystr())

c = canvas.canvas()
c.insert(axis.pathaxis(p, axis.log(min=1e-16, max=1, texter=mytexter)))
c.writeEPSfile("log")
c.writePDFfile("log")
--------------------------------------------------

Michael.


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to