Hi Neal,
The inverse coord transformations accept log values for logarithmic
axes, that is correct.
In order to convert the number back to the correct number, you should use
x coord inv trafo/.code={%
\pgfplotscoordmath{x}{exp}{#1}%
\show\pgfmathresult
\expandafter\secondspp\expandafter{\pgfmathresult}}
the "coordmath" stuff ensures a suitable precision and respects the
correct log basis. It assigns the result to \pgfmathresult.
Your \secondspp seems to overwrite \pgfmathresult, that's why I used the
two \expandafter constructs to pass by value instead of by reference.
PGFplots assumes that user-provided transformations fit into the axis,
i.e. that the transformation "knows" that it is to be applied in a log
context. Consequently, you'd need two transformations, one tailored for
linear axes and one tailored for log axes. This could be done by means
of styles.
I hope this helps so far.
Best regards
Christian
Am 16.01.2013 14:10, schrieb Neal H. Walfield:
> Hi,
>
> I'm using x coord inv trafo/.code to transform seconds into more
> (human) meaningful labels. For instance, my macro turns 7000 seconds
> into '2h'. This works correctly for normal axes, however, if I use a
> logarithmic axes, my macro is passed the exponent rather than the
> value. How do I programmatically determine what I am being passed?
>
> A minimal example follows.
>
> Thanks for your help,
>
> Neal
>
>
> \documentclass{article}
>
> \usepackage{tikz}
> \usepackage{pgfplots}
>
> % number
> % threshold
> % divisor
> % suffix
> % else
> \def\secondspphelper#1#2#3#4#5{%
> \pgfmathfloatparsenumber{#1}%
> \edef\num{\pgfmathresult}%
> \pgfmathfloatparsenumber{#2}%
> \edef\threshold{\pgfmathresult}%
> \pgfmathfloatparsenumber{#3}%
> \edef\divisor{\pgfmathresult}%
> %
> \pgfmathfloatlessthan{\num}{\threshold}%
> \ifdim\pgfmathresult pt = 1 pt%
> \pgfmathfloatdivide{\num}{\divisor}%
> \pgfmathfloattofixed{\pgfmathresult}%
> \pgfmathprintnumberto[/pgf/number
> format/precision=0]{\pgfmathresult}{\pgfmathresult}%
> \edef\pgfmathresult{\pgfmathresult#4}%
> \else%
> #5%
> \fi%
> }%
>
> % Pretty print a number of seconds.
> % Example:
> % \secondspp{1000}\pgfmathresult == 17m
> \def\secondspp#1{%
> % Print as seconds for values up to 90 seconds.
> \secondspphelper{#1}{90}{1}{s}{%
> % Print as minutes for values up to 1 hour (= 3600 seconds)
> \secondspphelper{#1}{3600}{60}{m}{%
> % Print as hours for values up to 1 day (= 86400 seconds)
> \secondspphelper{#1}{86400}{3600}{h}{%
> % Print as days for up to 2 weeks (= 1209600 seconds)
> \secondspphelper{#1}{1209600}{86400}{d}{%
> % Print as weeks.
> \secondspphelper{#1}{Inf}{604800}{w}{}%
> }%
> }%
> }%
> }%
> }
>
> \begin{document}
>
> \def\xmin{1}
> \def\xmax{10000}
>
> \begin{tikzpicture}
> \begin{axis}[
> xticklabel={\tick},
> scaled x ticks=false,
> plot coordinates/math parser=false,
> x coord inv trafo/.code={\def\x{#1}\show\x\secondspp{#1}}
> ]
> \addplot[domain=\xmin:\xmax] plot expression {x};
> \end{axis}
> \end{tikzpicture}
>
> \begin{tikzpicture}
> \begin{loglogaxis}[
> xticklabel={\tick},
> scaled x ticks=false,
> plot coordinates/math parser=false,
> x coord inv trafo/.code={\def\x{#1}\show\x\secondspp{#1}}
> ]
> \addplot[domain=\xmin:\xmax] plot expression {x};
> \end{loglogaxis}
> \end{tikzpicture}
>
> \end{document}
>
>
> ------------------------------------------------------------------------------
> Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
> and much more. Keep your Java skills current with LearnJavaNow -
> 200+ hours of step-by-step video tutorials by Java experts.
> SALE $49.99 this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122612
> _______________________________________________
> Pgfplots-features mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pgfplots-features
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122912
_______________________________________________
Pgfplots-features mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pgfplots-features