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}

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}

ymaxto3and uncommenting theyticklabelline. The problem seems to be that the rounding algorithm stumbles if you give it too many trailing zeros: PGFplots passes1.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