[Tex/LaTex] Plotting .dat file in pgfplot with multiple columns

pgfplots

I'm trying to use pgfplots with a .dat file to plot multiple data points on a graph, but for some reason it's plotting the same two columns over and over again, what have I done wrong?. The .dat file I'm using looks like this:

eang    disppos dispvel dispacc 
0.0000  50.0000 0.0000  -32.8125
1.0000  49.9950 -0.5726 -32.8043
2.0000  49.9800 -1.1450 -32.7796
3.0000  49.9550 -1.7168 -32.7386
4.0000  49.9201 -2.2877 -32.6811
5.0000  49.8752 -2.8575 -32.6073
6.0000  49.8204 -3.4258 -32.5172
7.0000  49.7556 -3.9924 -32.4108
8.0000  49.6810 -4.5571 -32.2882
9.0000  49.5966 -5.1194 -32.1495
10.0000 49.5023 -5.6792 -31.9948  
11.0000 49.3983 -6.2361 -31.8241
12.0000 49.2847 -6.7900 -31.6376
13.0000 49.1613 -7.3404 -31.4354
14.0000 49.0284 -7.8872 -31.2176
15.0000 48.8860 -8.4300 -30.9844
16.0000 48.7342 -8.9687 -30.7358
17.0000 48.5730 -9.5028 -30.4721

\pgfplotstableread{pistonkinetics.dat}{\pistonkinetics}
\begin{tikzpicture}[scale=1]
\begin{axis}[minor tick num=1,
xlabel=Degrees]
\addplot [x={eang}, y={disppos},black,very thick] table {\pistonkinetics};
\addplot [x={eang}, y={dispvel},dashed,red,very thick] table {\pistonkinetics};
\addplot [x={eang}, y={dispacc},dashed,blue,very thick] table {\pistonkinetics};
\end{axis}
\end{tikzpicture}

Best Answer

The x and y options need to be supplied to the table part of the \addplot command, not to \addplot itself:

\documentclass[]{article}
\usepackage{filecontents,pgfplots}

\begin{filecontents}{pistonkinetics.dat}
eang    disppos dispvel dispacc 
0.0000  50.0000 0.0000  -32.8125
1.0000  49.9950 -0.5726 -32.8043
2.0000  49.9800 -1.1450 -32.7796
3.0000  49.9550 -1.7168 -32.7386
4.0000  49.9201 -2.2877 -32.6811
5.0000  49.8752 -2.8575 -32.6073
6.0000  49.8204 -3.4258 -32.5172
7.0000  49.7556 -3.9924 -32.4108
8.0000  49.6810 -4.5571 -32.2882
9.0000  49.5966 -5.1194 -32.1495
10.0000 49.5023 -5.6792 -31.9948  
11.0000 49.3983 -6.2361 -31.8241
12.0000 49.2847 -6.7900 -31.6376
13.0000 49.1613 -7.3404 -31.4354
14.0000 49.0284 -7.8872 -31.2176
15.0000 48.8860 -8.4300 -30.9844
16.0000 48.7342 -8.9687 -30.7358
17.0000 48.5730 -9.5028 -30.4721
\end{filecontents}

\begin{document}
\pgfplotstableread{pistonkinetics.dat}{\pistonkinetics}
\begin{tikzpicture}[scale=1]
\begin{axis}[minor tick num=1,
xlabel=Degrees]
\addplot [black,very thick] table [x={eang}, y={disppos}] {\pistonkinetics};
\addplot [dashed,red,very thick] table [x={eang}, y={dispvel}] {\pistonkinetics};
\addplot [dashed,blue,very thick] table [x={eang}, y={dispacc}] {\pistonkinetics};
\end{axis}
\end{tikzpicture}
\end{document}