# Accessing the n-th coordinates of a plot

\begin{tikzpicture}
\begin{axis}
(1,1) (2,4) (3,9) (4,16)
};
\draw (axis cs:0,0) -- (axis cs:3,9);
\end{axis}
\end{tikzpicture}


I can easily draw a line between two points in a coordinate system. Here, I got a few coordinates of y=x². I can draw a line from the origin of the coordinate system (0,0) to (3,9), which is laying on the plot. (3,9) is the 3rd coordinate of the plot. Would it be possible to write somthing like

\draw (axis cs:0,0) -- (plotcs:3);


to access the coordinates of the 3rd tuple in a plot?

-

I put the table into a file data.dat:

% y = x^2
xcol   ycol
1      1
2      4
3      9
4     16


And could access the coordinates via pgfplotstable package:

\begin{tikzpicture}
\begin{axis}
\pgfplotstablegetelem{2}{xcol}\of{\mytable}     %% get n-th x
\pgfmathsetmacro{\xn}{\pgfplotsretval}
\pgfplotstablegetelem{2}{ycol}\of{\mytable}     %% get n-th y
\pgfmathsetmacro{\yn}{\pgfplotsretval}
\path[draw] (axis cs:0,0) -- (axis cs:\xn,\yn); %% draw line
\end{axis}
\end{tikzpicture}

-