
我有一個包含 3 列 X、Y 和 Z 的資料檔。
X Y Z
# datas from the natural movement of a robot
0.0000000e+00 3.3891017e-01 -1.3249598e-01
2.0000000e-02 3.3675858e-01 -1.3535520e-01
4.0000000e-02 3.3470984e-01 -1.3826038e-01
6.0000000e-02 3.3287897e-01 -1.4130291e-01
8.0000000e-02 3.3136947e-01 -1.4456564e-01
我想要一個可以顯示 Y(X) 或 Z(X) 的圖表。我能怎麼做?
我試過
\documentclass{standalone}
\usepackage{pgfplots}
% \usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{width=7cm}
\begin{axis} [title= two curves]
\addplot [blue, x=X, y=Y] table
{myfile.dat};
\addplot [red, x=X, y=Z] table
{myfile.dat};
\legend{$y(x)$,$z(x)$}
\end{axis}
\end{tikzpicture}
\end{document}
但輸出始終是 Y(X)。
答案1
表選項應該轉到table
關鍵字而不是然後\addplot
它可以工作
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\pgfplotstableread[]{
X Y Z
0.0000000e+00 3.3891017e-01 -1.3249598e-01
2.0000000e-02 3.3675858e-01 -1.3535520e-01
4.0000000e-02 3.3470984e-01 -1.3826038e-01
6.0000000e-02 3.3287897e-01 -1.4130291e-01
8.0000000e-02 3.3136947e-01 -1.4456564e-01
}\mytable
\begin{tikzpicture}
\begin{axis} [width=7cm,title= two curves]
\addplot[blue] table [x=X, y=Y] {\mytable};
\addplot[red] table [x=X, y=Z] {\mytable};
\legend{$y(x)$,$z(x)$}
\end{axis}
\end{tikzpicture}
\end{document}