Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to position nodes near coords at the bottom of the corresponding bar, right by the X axis.

Here's what I've got now:

\documentclass{report}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
            ybar,
            ymin=0, yticklabel style={/pgf/number format/fixed},
            symbolic x coords={0,1,2,3}, enlarge x limits=0.15,
            every node near coord/.append style={font=\tiny, yshift=-30}]        
        \addplot+ [nodes near coords, point meta=explicit symbolic]
            table[x index=0, y index=1, meta index=3] {
                0   0.1872  0.0040  0
                1   0.0358  0.0017  22
                2   0.0358  0.0017  23
                3   0.0358  0.0017  24
            };
    \end{axis}
\end{tikzpicture}
\end{document}

I assume if I could write something like yshift=\getcurrentvalueofy (or yshift=\getbarheight), the problem would be solved. I tried \pgfkeysvalueof{/data point/y}, but I must admit I did not really understand what I was doing, so it did not work out.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

You can make the value of the y coordinate available using the key visualization depends on=y \as \rawy (where \rawy is a macro name you choose). Then you can shift the nodes using shift={(axis direction cs:0,-\rawy)}. Note that you'll have to use axis direction cs because the coordinate system is shifted and scaled at the time when the nodes are placed.

\documentclass{report}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
            ybar,
            ymin=0, yticklabel style={/pgf/number format/fixed},
            visualization depends on=y \as \rawy,
            symbolic x coords={0,1,2,3}, enlarge x limits=0.15,
            every node near coord/.append style={
                    font=\tiny,
                    shift={(axis direction cs:0,-\rawy)}
                }
        ]        
        \addplot+ [nodes near coords, point meta=explicit symbolic]
            table[x index=0, y index=1, meta index=3] {
                0   0.1872  0.0040  0
                1   0.0358  0.0017  22
                2   0.0358  0.0017  23
                3   0.0358  0.0017  24
            };
    \end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.