Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.