[Tex/LaTex] Import selected rows without header in pgfplots

graphsimportpgfplotstikz-pgf

Import of selected rows of a data set (without header line)

The import should make use of the column numbers instead of row headers. The pgfplots' manual presents the possibility to use the command \thisrowno{} that takes a number in $\mathbbm{N}_0$.

Similar MWE that works fine

The following example works (without error message) but is not what is intended:

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

enter image description here

Best Answer

The difference to the MWE in the question is that \thisrow{} or \thisrowno{} need a different argument in the table's options, i.e. instead of

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

the following command shows the identical result

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

or with row numbers (without header line):

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