5

I wish to draw two pins on a plot:

\documentclass{standalone}
\usepackage{pgfplots,tikz}
\begin{document}
\begin{tikzpicture}
 \begin{axis}
  \addplot {x^2} node[pos=1,pin={[pin distance=0.5em, rounded corners, red, draw=red, fill=red!10!white]20:{$c$}}] {}
  node[pos=0.8,pin={[pin distance=0.5em, rounded corners, red, draw=red, fill=red!10!white]20:{$c$}}] {};
 \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

As you can see, the top-right pin is behind the axes and therefore is clipped and partially unreadable. Is there a way to alter the z-axis ordering of the nodes so that the pin is in front of the rest of the image and thus is not cropped?

  • 2
    A quick fix is to give the option clip=false but if your plot extends beyond the axis limits it's not good enough. A better approach is to put the TikZ commands inside the after end axis/.code. There must be a recent question about this but I couldn't retrieve it.... Here it is tex.stackexchange.com/questions/119821/… – percusse Jun 20 '13 at 9:17
7

You can add option clip=false to axis and will see a complete pin. Your top pin is not behind the axes but just partially outside.

\documentclass{standalone}
\usepackage{pgfplots,tikz}
\begin{document}
\begin{tikzpicture}
 \begin{axis}[clip=false]
  \addplot {x^2} node[pos=1,pin={[pin distance=0.5em, rounded corners, red, draw=red, fill=red!10!white]20:{$c$}}] {}
  node[pos=0.8,pin={[pin distance=0.5em, rounded corners, red, draw=red, fill=red!10!white]20:{$c$}}] {};
 \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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