TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

I want to plot data from a file using Tikz. I have a data file with 5 columns of data, and I want, for example to plot column 1 and 3 together. How can I make Tikz load the data from the correct columns?

Example of data file:


Current Latex:

\draw[color=blue] plot[smooth,mark=*,mark size=1pt] file {data.dat} node [right] {data};
share|improve this question
up vote 26 down vote accepted

You should use the \addplot table command from pgfplots. The x index=0 and y index=2 specify which column is to be selected (numbering starts from 0). I have two \addplot commands to plot each column separately.



\begin{axis}[xlabel={$x$},ylabel={Column Data}]

% Graph column 2 versus column 0
\addplot table[x index=0,y index=2,col sep=comma] {datax.dat};
\addlegendentry{Column 3}% y index+1 since humans count from 1

% Graph column 1 versus column 0    
\addplot table[x index=0,y index=1,col sep=comma] {datax.dat};
\addlegendentry{Column 2}


enter image description here

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.