# Making an arrow in a pgfplot figure from one point to another?

How can I make an arrow from one point in a tikz picture to another point?

In the following example, I would like to draw an arrow from the word data--which is approximately the coordinate (1982, 88)-- and have it point to the coordinate (1985, 82).

\documentclass[professionalfont, fleqn]{beamer}
\mode<presentation>
\usetheme{Warsaw}
\usetheme{CambridgeUS}

\usepackage{pgfplots}
\usetikzlibrary{arrows,shapes,positioning}
\graphicspath{{graphics/}}

\begin{document}
\frame
{
\frametitle{Frame Title}
\begin{tikzpicture}
\begin{axis}
[
axis x line  = bottom,
axis y line  = left,
width        = 1.01\textwidth,
height       = .63\textwidth,          % Adjusted
ymax         = 93,
ymin         = 27,
ytick        = {30,40,...,90},
xmax         = 1993,
xmin         = 1967,
xtick        = {1970, 1980, ..., 1990},
]
\node[anchor=west] at (axis cs:1968.5,89.5){%
\textbullet\ Comment here about data
};
\end{axis}
\end{tikzpicture}
}

\end{document}

-

## 3 Answers

You can do this using nodes, such as

       \node[anchor=west] (source) at (axis cs:1968.5,89.5){\textbullet\ Comment here about data};
\node (destination) at (axis cs:1985,82){};
\draw[->](source)--(destination);


which gives

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}
[
axis x line  = bottom,
axis y line  = left,
width        = 1.01\textwidth,
height       = .63\textwidth,          % Adjusted
ymax         = 93,
ymin         = 27,
ytick        = {30,40,...,90},
xmax         = 1993,
xmin         = 1967,
xtick        = {1970, 1980, ..., 1990},
]
\node[anchor=west] (source) at (axis cs:1968.5,89.5){\textbullet\ Comment here about data};
\node (destination) at (axis cs:1985,82){};
\draw[->](source)--(destination);
\end{axis}
\end{tikzpicture}

\end{document}


Following the comment, you can connect nodes using many different ways (See Section 3.10 of the tikz & pgf manual); you can also customize the arrows (see Section 23 of the manual). For example,

\draw[->,>=stealth](source) to [out=90,in=90] (destination);


gives

-
Thank you for your help! That works beautifully. Is it possible to draw the arrow such that the arrowhead is a little thicker? Also, is it possible to make the arrow part curvy rather than linear? That is, say a circle going from 9 o'clock to 6 o'clock (or 9 to 12)? –  J G Feb 8 '12 at 22:06
@JG You're welcome :) See my edit. Welcome to tex exchange- the best way to say thanks is to upvote answers :) Note that you can upvote more than one answer on every question- it means that folks get 10 points for their time & code –  cmhughes Feb 8 '12 at 22:27
I tried to upvote. I have no idea if it worked. Do you know if it did? –  J G Feb 8 '12 at 23:44
@JG I can't tell who voted- if the up arrow is coloured brown, then you've done it :) –  cmhughes Feb 9 '12 at 1:57
The to example here requires that clip=false be set so that it is visible. –  Peter Grill Oct 12 '12 at 17:49

You can directly draw using coordinates:

\draw[->] (axis cs:1982, 88) -- (axis cs:1985, 82);


within the axes environment works. I posted the answer to the same question which has been posted a bit earlier on LaTeX-Community.org.

Much thicker arrow, as requested in the comment:

\draw[->,-triangle 60] (axis cs:1982, 88) -- (axis cs:1985, 82);


or triangle 45, triangle 90. The arrows library offers some. And for a thicker arrow as a whole, add the thick or very thick option to draw.

And for a curvy arrow you could use the bend option, such as

\draw[->,-triangle 60] (axis cs:1982, 88) to[bend right=-60] (axis cs:1985, 82);


-

Just to complete the answers on curvy arrows given before:
I found a solution I was being inspired by this article focusing on gnuplot.

Section 14.10 of the tikz & pgf manual provides a similar method by using a parabola to draw a curved arrow between two points. That method gives you some control over how the curve of the arrow should look beyond what can be achieved by the in and out options of the to operation, but easier to use than Bézier curves (section 14.3 of the manual).

You should get a nicely curved arrow by extending your example with the following:

\draw[->,>=stealth](source) parabola bend (axis cs:1980,40) (destination);


Unfortunately I couldn't post a picture of the result since this is my first post thanks to @diabonas comment:( :).

-
Welcome to TeX.sx! As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again. –  diabonas Oct 12 '12 at 15:25
Thanks! Your comment made the help of others unnecessary ;). –  jhn Oct 12 '12 at 16:56