Take the 2-minute tour ×
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.

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}
share|improve this question

1 Answer 1

up vote 9 down vote accepted

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}
share|improve this answer
    
Thanks Jake, its working for me now. –  Andy Feb 15 '12 at 12:47
1  
That's great! You can mark this question as answered by clicking the green check mark next to the answer. –  Jake Feb 15 '12 at 12:51
    
If you have a function, say sin(x), is there any way to put in an x axis at y=0 whilst retaining the box layout? I've tried [axis x line=center], but this gets rid of the box around the outside and brings the tick labels in, I just want the line. –  Andy Feb 15 '12 at 13:16
    
You can add extra description/.append code={\draw ({axis cs:0,0}-|{rel axis cs:0,0}) -- ({axis cs:0,0}-|{rel axis cs:1,0});} to your axis options to draw the 0 line. –  Jake Feb 15 '12 at 13:26

Your Answer

 
discard

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.