[Tex/LaTex] number format in pgfplots axis

formattingpgfplotspunctuation

How can I change the type of the decimal/thousand separator from the american one to the european one? More precisely, I want:

  • "1000" to be written as is, instead of "1,000"
  • "0,1" instead of "0.1"

Best Answer

The number formatting is changed using the /pgf/number format keys, which are described starting on page 546 of the pgfmanual. In your case, you would want to set /pgf/number format/use comma to set the comma as the decimal separator, and /pgf/number format/1000 sep={} to suppress separators for the groups of thousands.

When setting several subkeys, you can save yourself a bit of typing by first changing to the main key using /pgf/number format/.cd, and then setting the number formats.

Since I assume you want the number format to be consistent all through your plot, you should set the options for the whole axis.

Here's an example:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}


\begin{tikzpicture}
\begin{axis}[
    /pgf/number format/.cd,
        use comma,
        1000 sep={}]
\addplot +[domain=0:1] {(x+rnd)*4000};
\end{axis}
\end{tikzpicture}

\end{document}