匯入資料集的選定行(無標題行)

匯入資料集的選定行(無標題行)

匯入資料集的選定行(無標題行)

匯入應使用列號而不是行標題。 pgfplots 的手冊提供了使用\thisrowno{}在 $\mathbbm{N}_0$ 中獲取數字的命令的可能性。

類似的 MWE 運作良好

以下範例有效(沒有錯誤訊息),但不是預期的效果:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{filecontents}
\begin{filecontents*}{data.dat}
aasd dasdf basdf casdf
1 4 5 1
2 3 1 5
3 5 6 1
4 1 4 9
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
\begin{axis}[%
    xlabel={xlabel},
    ylabel={ylabel}]
\addplot[color=blue,mark=none] 
    table [x=aasd, y=casdf, col sep=space] {data.dat};
\addplot[color=red, mark=none] 
    table [x=aasd, y=basdf, col sep=space] {data.dat};
\end{axis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

答案1

與問題中的 MWE 的區別在於,\thisrow{}\thisrowno{}需要在表的選項中使用不同的參數,即而不是

\addplot[mark=none] 
    table [x=aasd, y=casdf, col sep=space] {data.dat};

以下命令顯示相同的結果

\addplot[mark=none] 
    table [x expr=\thisrow{aasd}, y expr=\thisrow{casdf}, col sep=space] {data.dat};

或使用行號(不含標題行):

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{filecontents}
\begin{filecontents*}{data.dat}
1 4 5 1
2 3 1 5
3 5 6 1
4 1 4 9
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
\begin{axis}[%
    xlabel={xlabel},
    ylabel={ylabel}]
\addplot[color=blue,mark=none] 
    table [x expr=\thisrowno{0}, y expr=\thisrowno{3}, col sep=space] {data.dat};
\addplot[color=blue,mark=none] 
    table [x expr=\thisrowno{0}, y expr=\thisrowno{2}, col sep=space] {data.dat};
\end{axis}
\end{tikzpicture}
\end{document}

相關內容