[Tex/LaTex] pgfplot: Pin drawn on top of ybar stacked plot

pgfplotstikz-pgf

I need to label some components of a stacked bar plot in pgfplot, and I would like the pin to be visible to the center (rather than the edge). I believe it is currently being drawn to the center of the bar (I can see it with no fill) but that it is being drawn under/before the bar.

I haven't found a reasonable way to do this, and it feels like there should be one. My actual plot is more complicated than this, so I would rather not draw the entire thing in tikz.

Here is the code and image showing the pin-to-center showing with no fill:

\documentclass{article} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\begin{document}
      \begin{tikzpicture}
        \begin{axis}[ybar stacked,
          enlarge x limits=0.3,
            ymin=0]

          \addplot coordinates {(1,1)};
          \addplot[] coordinates {(1,1)};

          \node[coordinate,pin=right :{A}] at (axis cs:1,0.5) {};
          \node[coordinate,pin=right :{B}] at (axis cs:1,1.5) {};
       \end{axis}
      \end{tikzpicture}

\end{document}

Pinning label to bar plot

Apologies if I have completely missed something obvious!

Best Answer

You can draw the pins before the bar:

\documentclass{article} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\begin{document}
      \begin{tikzpicture}
        \begin{axis}[ybar stacked,
          enlarge x limits=0.3,
            ymin=0]

          \node[coordinate,pin=right :{A}] at (axis cs:1,0.5) {};
          \node[coordinate,pin=right :{B}] at (axis cs:1,1.5) {};
          \addplot coordinates {(1,1)};
          \addplot[] coordinates {(1,1)};

       \end{axis}
      \end{tikzpicture}

\end{document}

enter image description here

Related Question