在 pgfplot 中绘制具有多列的 .dat 文件

在 pgfplot 中绘制具有多列的 .dat 文件

我正在尝试使用pgfplots一个.dat文件在图表上绘制多个数据点,但出于某种原因,它一遍又一遍地绘制相同的两列,我做错了什么?.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

\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}

答案1

x和选项y需要提供给命令table的一部分\addplot,而不是\addplot命令本身:

\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}

相关内容