4

I was just trying to compile some data into a bar chart using pgfplots. Things seem to work apart from the following: The annotation for the bars has low precision, i.e. only 3 decimals, it is shown as "1.02 \cdot 10^6". Is there a way to change it to the actual value (1022641)?

\begin{tikzpicture}
    \begin{axis}[
    xbar, xmin=500000,
    width=12cm,enlarge y limits=0.5,
    xlabel={Travel time [s]},
    symbolic y coords={hello},
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    ]

    \addplot coordinates {(1022641,hello)};
    \end{axis}
\end{tikzpicture}
3
  • Add every node near coord/.append style={/pgf/number format/.cd, fixed,1000 sep={}} to your options.
    – percusse
    Apr 17, 2015 at 14:01
  • I added it like so: \begin{tikzpicture}[every node ...] but no change
    – hfhc2
    Apr 17, 2015 at 14:05
  • @hfhc2: Add it to \begin{axis}[...], or add it as \begin{tikzpicture}[/pgfplots/every node ...].
    – Jake
    Apr 17, 2015 at 14:07

1 Answer 1

1

Ok, I ended up doing the following: I first defined a style outside of the actual \tikzpicture:

\pgfplotsset{
    default style/.style={
    xbar, xmin=0,
    width=12cm,enlarge y limits=0.5,
    xlabel={Travel time [s]},
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    every node near coord/.append style={/pgf/number format/.cd, fixed,1000 sep={}}
    }
}

which contains the modification which percusse and Jake suggested. The actual plot uses the defined style:

\begin{tikzpicture}
    \begin{axis}[
    default style,
    symbolic y coords={hello}
    ]

    \addplot coordinates {(1022641,hello)};
    \end{axis}
\end{tikzpicture}

This way the style and the data are decoupled and the style is reusable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .