20

Consider the following example from the pgfplot manual.

\begin{tikzpicture}
  \tikzset{
    every pin/.style={fill=yellow!50!white,rectangle,rounded corners=3pt,font=\tiny},
    small dot/.style={fill=black,circle,scale=0.3}
  }
  \begin{axis}[
    clip=false,
    title=How \texttt{axis description cs} works
  ]
  \addplot {x};

  \node[small dot,pin=120:{$(0,0)$}]
  \node[small dot,pin=-30:{$(1,1)$}]
  \node[small dot,pin=-90:{$(1.03,0.5)$}]
  \node[small dot,pin=125:{$(0.5,0.5)$}]
  \end{axis}
\end{tikzpicture}

That code gives the following image

image produced by above code

What I want to change and I couldn't found in the manual is to change the length of the pins. For example make the text of the pin in the middle appear closer to the value 5 of the y axis and make the connecting line extent to that point. The result I want appears in the following picture.

enter image description here

Is that possible somehow?

1 Answers1

34

You can use pin distance:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
  \tikzset{
    every pin/.style={fill=yellow!50!white,rectangle,rounded corners=3pt,font=\tiny},
    small dot/.style={fill=black,circle,scale=0.3}
  }
  \begin{axis}[
    clip=false,
    title=How \texttt{axis description cs} works
  ]
  \addplot {x};

  \node[small dot,pin=120:{$(0,0)$}] at (axis description cs:0,0) {};
  \node[small dot,pin=-30:{$(1,1)$}] at (axis description cs:1,1) {};
  \node[small dot,pin={[pin distance=2cm]125:{$(0.5,0.5)$}}] at (axis description cs:0.5,0.5) {};
  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128