7

I have the opposite problem to this question. I want the decimal parts of an integer printed for consistency's sake. I already tried specifying the precision but without success. See below. an example

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,
nodes near coords, %={\pgfmathprintnumber[fixed,precision=2]{\pgfplotspointmeta}}
]
\addplot coordinates { (1,1.11) (2,2.22)(3,3.00)(4,4.44) };
\end{axis}
\end{tikzpicture}
\end{document}

Follow up question in response to Peter Grill's answer:

Is it possible to let this specifications only affect the nodes over the bars and let the axis ticks stay without additional decimal parts? That would be the high point.

Answer: By chance I already found the answer to that one myself. Setting

\pgfkeys{
    /pgf/number format/precision=0, 
    /pgf/number format/fixed zerofill=true }

to 0 and using

nodes near coords={\pgfmathprintnumber[fixed,precision=2]{\pgfplotspointmeta}}

in the axis-specifications, I get "normal " integers on the axes and enforced decimal parts in the chart itself.

meep.meep
  • 16,905
  • Your title asks about pgfmath, but your example is using pgfplots, which is not the same. Please change the title accordantly if this question is directly targeted on pgfplots, not pgfmath macros in general. – Martin Scharrer Feb 02 '12 at 16:28
  • @MartinScharrer: Of course I will change the title if it's flawed. Truth be told, my knowledge of pgfplots and pgfmath is basic at best. I encountered this problem by using pgfplots and deducted from posts such as the linked one that there must be something as pgfmath at work here. So if someone knows what the better title would be, please tell me and I'll change it accordingly. – meep.meep Feb 03 '12 at 09:23

1 Answers1

9

You need:

/pgf/number format/precision=1, 
/pgf/number format/fixed zerofill=true

enter image description here

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\pgfkeys{
    /pgf/number format/precision=1, 
    /pgf/number format/fixed zerofill=true
}

\begin{axis}[ybar, nodes near coords]
\addplot coordinates { (1,1.11) (2,2.22)(3,3.00)(4,4.44) };
\end{axis}
\end{tikzpicture}
\end{document}
Peter Grill
  • 223,288