
X, Y, Z 3개의 열이 포함된 데이터 파일이 있습니다.
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}