70

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"
lockstep
  • 250,273

2 Answers2

77

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}

Jake
  • 232,450
  • Do you know if it is possible to have pgfplots(and TikZ) to format numbers like \num{} from the siunitx package (ftp://ftp.dante.de/tex-archive/help/Catalogue/entries/siunitx.html). -Like my numbers in the rest of the document. – hpekristiansen Dec 10 '11 at 17:50
  • 3
    @Hans-PeterE.Kristiansen: Yes, you can set xticklabel=\num[round-mode=places,round-precision=1]{\tick} (or similar). – Jake Dec 11 '11 at 01:24
  • 2
    I think a new option like american number format or european number format could be useful here (this is a comment for @ChristianFeuersänger). Otherwise, if one uses siunitx, the number format should be gathered from the options set in that package. – Luigi Dec 17 '12 at 16:55
  • For version 3.0.1a, the description of the pgf/number format keys start page 945. – bli Jun 08 '17 at 16:06
16

Edit: As per Jake's comments: using set decimal separator={,} instead of use comma introduces an unwanted thin space after the comma. Interestingly, if you use set decimal separator={.}, this doesn't happen. So, better to use use comma instead as per Jake's solution.


Use set thousands separator={} and set decimal separator={,} which yields:

enter image description here

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
      y tick label style={/pgf/number format/.cd,%
          scaled y ticks = false,
          set thousands separator={},
          fixed},
      x tick label style={/pgf/number format/.cd,%
          scaled x ticks = false,
          set decimal separator={,},
          fixed}%
     ]
  \addplot coordinates {
  (0.1,1000)
  (0.2,1100)
  (0.3,1200)
  };    
\end{axis}
\end{tikzpicture}
\end{document}
Peter Grill
  • 223,288
  • Use set decimal separator={{,}} to avoid this behavior. – Patrick Bergner Dec 23 '12 at 18:45
  • @PatrickBergner I have tried this and it is not improving the situation. Any idea? – Magpie Mar 10 '13 at 14:34
  • @Magpie: Without more details it is difficult to help. I'd suggest posting a new question. You should refer to this question and show exactly how this did not improve the situation. – Peter Grill Mar 10 '13 at 20:49
  • @PeterGrill it's ok I fixed it. See answer below. Thanks! – Magpie Mar 10 '13 at 21:27
  • Oh wait.I just noticed that the OP actually wanted this formatting I can't get my head around that but I will delete anyway. – Magpie Mar 10 '13 at 21:36
  • 1
    @Magpie: In some countries (like Germany) a comma is used as the decimal separator and a period as the thousands separator. It's just a convention. – Jake Mar 10 '13 at 23:43
  • I thought the language of mathematics was universal. What fresh hell is this? – Magpie Mar 11 '13 at 00:15
  • 2
    @Magpie is called i18n. Number notation is more a language (local) matter than mathematics. Traditional Spanish, for example, is using a raised comma for decimal separation, and a dot for thousand separator. Italy has a similar convention, just with standard comma. Could be hell, but it is in the same category of hell as "why don't anyone speak English?" ;-) – Rmano Jan 21 '16 at 11:05