Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## pyx-user

 [PyX-user] Metric prefixes on axis? From: Thomas Kornack - 2007-04-25 16:27:42 Hello folks: 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! Tom 
 Re: [PyX-user] Metric prefixes on axis? From: Michael SCHINDLER - 2007-04-26 23:34:42 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. 
 Re: [PyX-user] Metric prefixes on axis? From: Gert Ingold - 2007-05-04 06:55:24 Attachments: Message as HTML Salut Michael, > 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. =20 This might be a good opportunity to make use of the units-package. Your example then becomes ------------------------------------------------------------ import math from pyx import * from pyx.graph import axis text.set(mode=3D"latex") text.preamble(r"\usepackage{units}") class mystr(str): prefixes =3D [ (3, "M"), (0, ""), (-1, "d"), (-2, "c"), (-3, "m"), (-6, r"\mu{}"), (-9, "n"), (-12, "p"), (-15, "f"), (-18, "a")] def __mod__(self, otherstr): other =3D int(otherstr) for expon, pref in self.prefixes: if other >=3D expon: break o, p =3D other, pref return r"\unit[%d]{%sT}" % (10**(other-expon), pref) p =3D path.curve(0, 0, 3, 0, 1, 4, 4, 4) mytexter =3D axis.texter.exponential(nomantissaexp=3Dmystr()) c =3D canvas.canvas() c.insert(axis.pathaxis(p, axis.log(min=3D1e-16, max=3D1, texter=3Dmytexter)= )) c.writeEPSfile("log") c.writePDFfile("log") ------------------------------------------------------------ Best regards, Gert --=20 Gert-Ludwig Ingold email: Gert.Ingold@... Institut f=FCr Physik Phone: +49-821-598-3234 Universit=E4t Augsburg Fax : +49-821-598-3222 D-86135 Augsburg WWW : http://www.physik.uni-augsburg.de/theo1/ingold Germany PGP : 86FF5A93, key available from homepage