![如何选择 dat 文件的一列在 pgfplot 中绘图?](https://linux22.com/image/327696/%E5%A6%82%E4%BD%95%E9%80%89%E6%8B%A9%20dat%20%E6%96%87%E4%BB%B6%E7%9A%84%E4%B8%80%E5%88%97%E5%9C%A8%20pgfplot%20%E4%B8%AD%E7%BB%98%E5%9B%BE%EF%BC%9F.png)
我有 dat 文件(Matlab 输出),它有四列。我该如何选择所需的列来在 pgfplots 中绘制。
\documentclass{article}
\usepackage[active,tightpage]{preview}
\usepackage{varwidth}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\usepackage[active,tightpage]{preview}
\usepackage{varwidth}
\begin{tikzpicture}
\boldmath
\pgfplotsset{every axis/.append style={line width=1.2pt}}
\pgfplotsset{every tick/.append style={color=black}}
\pgfplotsset{every minor tick/.append style={thin}}
\pgfplotsset{every major tick/.append style={line width=1pt}} %
\begin{axis}[]
\addplot+[very thick,mark=triangle*,mark repeat=1,mark options={scale=1.3}] file{Fre.dat};
\addlegendentry{ $column1-2$}
\end{axis}
\end{tikzpicture}
\end{document}
我的数据文件是:
0.0000000e+00 9.7322390e+00 1.3985949e+01 1.5525350e+01
2.5000000e+00 9.7404206e+00 1.4001132e+01 1.5546305e+01
5.0000000e+00 9.7651029e+00 1.4046619e+01 1.5609681e+01
7.5000000e+00 9.8067018e+00 1.4122249e+01 1.5717003e+01
1.0000000e+01 9.8659247e+00 1.4227833e+01 1.5870771e+01
1.2500000e+01 9.9437917e+00 1.4363269e+01 1.6074399e+01
1.5000000e+01 1.0041667e+01 1.4528713e+01 1.6332129e+01
1.7500000e+01 1.0161304e+01 1.4724777e+01 1.6648943e+01
2.0000000e+01 1.0304897e+01 1.4952727e+01 1.7030511e+01
2.2500000e+01 1.0475157e+01 1.5214662e+01 1.7483207e+01
2.5000000e+01 1.0675401e+01 1.5513636e+01 1.8014219e+01
2.7500000e+01 1.0909671e+01 1.5853762e+01 1.8631749e+01
3.0000000e+01 1.1182876e+01 1.6240296e+01 1.9345313e+01
3.2500000e+01 1.1500982e+01 1.6679755e+01 2.0166108e+01
3.5000000e+01 1.1871246e+01 1.7180085e+01 2.1107451e+01
3.7500000e+01 1.2302522e+01 1.7750913e+01 2.2185310e+01
4.0000000e+01 1.2805653e+01 1.8403905e+01 2.3418947e+01
4.2500000e+01 1.3393986e+01 1.9153253e+01 2.4831704e+01
4.5000000e+01 1.4084049e+01 2.0016348e+01 2.6045676e+01
4.7500000e+01 1.4896463e+01 2.1014686e+01 2.7132868e+01
5.0000000e+01 1.5857171e+01 2.2175104e+01 2.8395420e+01
5.2500000e+01 1.6999148e+01 2.3531505e+01 2.9867785e+01
5.5000000e+01 1.8364789e+01 2.5127277e+01 3.1594083e+01
5.7500000e+01 2.0009352e+01 2.7018776e+01 3.3631631e+01
6.0000000e+01 2.2006006e+01 2.9280464e+01 3.6056144e+01
答案1
x index
您可以使用或键指定每个坐标的列索引y index
,如 中所示\addplot file [x index=0, y index=1] {Fre.dat};
。0 是第一列的索引,如中所述pgfplots
手动的第 4.3.2 节。
示例(删除了与当前问题无关的所有内容):
\documentclass[tikz,border=5pt]{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{filecontents*}{Fre.dat}
0.0000000e+00 9.7322390e+00 1.3985949e+01 1.5525350e+01
2.5000000e+00 9.7404206e+00 1.4001132e+01 1.5546305e+01
5.0000000e+00 9.7651029e+00 1.4046619e+01 1.5609681e+01
7.5000000e+00 9.8067018e+00 1.4122249e+01 1.5717003e+01
1.0000000e+01 9.8659247e+00 1.4227833e+01 1.5870771e+01
1.2500000e+01 9.9437917e+00 1.4363269e+01 1.6074399e+01
1.5000000e+01 1.0041667e+01 1.4528713e+01 1.6332129e+01
1.7500000e+01 1.0161304e+01 1.4724777e+01 1.6648943e+01
2.0000000e+01 1.0304897e+01 1.4952727e+01 1.7030511e+01
2.2500000e+01 1.0475157e+01 1.5214662e+01 1.7483207e+01
2.5000000e+01 1.0675401e+01 1.5513636e+01 1.8014219e+01
2.7500000e+01 1.0909671e+01 1.5853762e+01 1.8631749e+01
3.0000000e+01 1.1182876e+01 1.6240296e+01 1.9345313e+01
3.2500000e+01 1.1500982e+01 1.6679755e+01 2.0166108e+01
3.5000000e+01 1.1871246e+01 1.7180085e+01 2.1107451e+01
3.7500000e+01 1.2302522e+01 1.7750913e+01 2.2185310e+01
4.0000000e+01 1.2805653e+01 1.8403905e+01 2.3418947e+01
4.2500000e+01 1.3393986e+01 1.9153253e+01 2.4831704e+01
4.5000000e+01 1.4084049e+01 2.0016348e+01 2.6045676e+01
4.7500000e+01 1.4896463e+01 2.1014686e+01 2.7132868e+01
5.0000000e+01 1.5857171e+01 2.2175104e+01 2.8395420e+01
5.2500000e+01 1.6999148e+01 2.3531505e+01 2.9867785e+01
5.5000000e+01 1.8364789e+01 2.5127277e+01 3.1594083e+01
5.7500000e+01 2.0009352e+01 2.7018776e+01 3.3631631e+01
6.0000000e+01 2.2006006e+01 2.9280464e+01 3.6056144e+01
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot file [x index=0,y index=1] {Fre.dat};
\end{axis}
\end{tikzpicture}
\end{document}