3

I would like to know if I can use cases when taking input from a csv file: Instead of generating multiple csv files, I would like to do the following In my tex file:

Input from line 1-10 of file.csv draw plot1.
Input from line 11-20 of file.csv draw plot2.

I use the following in my tex file:

\addplot[red!30,fill] table[x="Param: length",y="Score", col sep=comma, ignore chars=\%,comment chars={T}] {file.csv};

which take as input all lines in the file.csv. But would like to add some improvements.

Thank you.

1
  • 1
    The second plot should be usable via option skip first n=10, but there is no skip last n. May 29, 2015 at 7:21

1 Answer 1

5

You can use restrict expr to domain={\coordindex}{0:9} (note that \coordindex uses zero-based indexing):

\documentclass{article}
\usepackage{pgfplots, filecontents}

\begin{filecontents}{data.dat}
1 10
2 11
3 9
4 12
5 10
6 11
7 9
8 10
9 12
10 9
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot +[restrict expr to domain={\coordindex}{0:4}] table {data.dat};
\addplot +[restrict expr to domain={\coordindex}{7:9}] table {data.dat};
\end{axis}
\end{tikzpicture}
\end{document}
6
  • Yes I have tried to add the exact line as you but I get an error, should I add restrict x to domain={\coordindex}{0:4}] and same for y ?
    – Bionix1441
    May 29, 2015 at 7:42
  • @Bionix1441: What error message do you get?
    – Jake
    May 29, 2015 at 7:47
  • ! Package pgfkeys Error: I do not know the key '/tikz/restrict x' and I am goin g to ignore it. Perhaps you misspelled it.
    – Bionix1441
    May 29, 2015 at 7:52
  • 1
    @Bionix1441: The key is called restrict expr to domain, not restrict x.
    – Jake
    May 29, 2015 at 7:54
  • I just tried this and it works, but only if restrict expr to domain is the first key in addplot's key list. Hope this might help for someone debugging this later on. Jul 3, 2015 at 9:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .