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 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!

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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

share|improve this answer
    
Wow, I really did miss the obvious thing! I assumed the drawing order was like in tikz with the later drawn things on top. –  ackey Sep 7 '11 at 4:18
add comment

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.