Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to make a the number format in my pgfplots the same, as in the rest of my document. I am normally using the \num from the siunitx package to typeset numbers, and would like to use it in my plots as well.

\num does not produce the same format as \pgfmathprintnumber, and I have tried this (thanks @Jake and @Marco Daniel):

\documentclass{standalone}
\usepackage{siunitx}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{semilogxaxis}
    [
    xmin=1, xmax=5000,
    ymin=0, ymax=2,
    log base 10 number format code/.code={ \pgfmathparse{10^(#1)}\num[round-mode=places, round-precision=0]{\pgfmathresult} },           %num version
    % log base 10 number format code/.code={$\pgfmathparse{10^(#1)}\pgfmathprintnumber[set thousands separator=\,]{\pgfmathresult}$}  %pgfmathprintnumber version
    % yticklabel={\num[round-mode=places, round-precision=1]{\tick}} %does not work
    ]
    \node at (axis cs: 10, 1.8) {\num[round-mode=places, round-precision=0]{12345678}};
    \node at (axis cs: 10, 1.7) {\pgfmathprintnumber[int detect, set thousands separator=\,]{12345678}};    
    \node at (axis cs: 10, 1.4) {\num[round-mode=places, round-precision=0]{1000}};
    \node at (axis cs: 10, 1.3) {\pgfmathprintnumber[int detect, set thousands separator=\,]{1000}};    
  \end{semilogxaxis}
  \end{tikzpicture}
\end{document}

Show number format

When ymax<3, the code for the yticklabel give the compile error:

! Number too big. \l_siunitx_tmpa_tl ->5000000000

Is there a solution to this problem, or some way to set the global number format used by pgfplots?


Here is the minimumcode, that is failing:

\documentclass{standalone}
\usepackage{siunitx}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{semilogxaxis}
    [
    xmin=1, xmax=5000,
    ymin=0, ymax=2,
    yticklabel={\num[round-mode=places, round-precision=1]{\tick}} %does not work
    ]
  \end{semilogxaxis}
  \end{tikzpicture}
\end{document}
share|improve this question
    
I've tried fiddling about with your code, and can't reproduce the fault. Could you edit the question so that there is one 'works' code block and one 'fails': this makes it a bit easier to follow the issues. –  Joseph Wright Dec 11 '11 at 12:21
    
@JosephWright: Done:o) –  Hans-Peter E. Kristiansen Dec 11 '11 at 12:39
1  
@JosephWright: I can reproduce the error by changing ymax to 3 and uncommenting the yticklabel line. The problem seems to be that the rounding algorithm stumbles if you give it too many trailing zeros: PGFplots passes 1.5000000000000. You can get the same error message with the minimal example \documentclass{article} \usepackage{siunitx} \begin{document} \num[round-mode=places]{1.5000000000000} \end{document} –  Jake Dec 11 '11 at 12:41
    
@Jake Currently, the rounding code uses TeX's number comparisons, etc. for speed. There's a balance between performance and flexibility. (How many people need to round really large numbers of digits?) I can take another look at this part of the code and see what I can do: may take a little while. –  Joseph Wright Dec 12 '11 at 12:16
    
I've logged this issue: bitbucket.org/josephwright/siunitx/issue/186/…. Hopefully I can fix it over the Christmas holiday. –  Joseph Wright Dec 13 '11 at 8:40
add comment

1 Answer 1

up vote 6 down vote accepted

As noted in the comments, this happens because the tick value is sometimes defined with a lot of trailing zeros, which causes a dimension too large error when siunitx tries to round the value. As a workaround, you could let \pgfmathparse clean up the value first by parsing it using \pgfmathparse{\tick*1} and then letting \num do its thing with \pgfmathresult:

\documentclass{standalone}
\usepackage{siunitx}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{semilogxaxis}
    [
    xmin=1, xmax=5000,
    ymin=0, ymax=2,
    yticklabel={\pgfmathparse{(\tick*1)}\num[round-mode=places, round-precision=1]{\pgfmathresult}}
    ]
  \end{semilogxaxis}
  \end{tikzpicture}
\end{document}
share|improve this answer
    
Is the '*1' because pgfmathparse insist on doing something? –  Hans-Peter E. Kristiansen Dec 13 '11 at 14:49
    
@Hans-PeterE.Kristiansen: No, it's because \pgfmathparse would just leave the number untouched if there's no operation. –  Jake Dec 13 '11 at 20:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.