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
Pgfplots-features@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pgfplots-features

Reply via email to