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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
    \addplot coordinates {
      (1,1) (2,4) (3,9) (4,16)
    \draw (axis cs:0,0) -- (axis cs:3,9);

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?

share|improve this question
up vote 2 down vote accepted

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:

    \pgfplotstableread{data.dat}{\mytable}          %% load table
    \addplot table[x=xcol,y=ycol] {\mytable};
    \pgfplotstablegetelem{2}{xcol}\of{\mytable}     %% get n-th x
    \pgfplotstablegetelem{2}{ycol}\of{\mytable}     %% get n-th y
    \path[draw] (axis cs:0,0) -- (axis cs:\xn,\yn); %% draw line
share|improve this answer

Your Answer


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.