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.

I have a data file from which I want to plot odd/even rows seperately, in the same axis. But the table options seem to apply only once, when reading in the data, which only happens once per axis (i.e. after a \nextgroupplot the data seems to be read again, or in a new tikzpicture).

\documentclass{article}
\usepackage{pgfplots}
\begin{filecontents}{data.dat}
1 1
2 4
3 3
4 8
\end{filecontents}
\begin{document}

\begin{tikzpicture}
    \begin{axis}
        \addplot[no markers] table[each nth point=2]{data.dat};
        \addplot[only marks] table[each nth point=2, skip first n=1]{data.dat};
    \end{axis}
\end{tikzpicture}

should be:

\begin{tikzpicture}
    \begin{axis}
        \addplot[no markers] table{
            1 1
            3 3
        };
        \addplot[only marks] table{
            2 4
            4 8
        };
    \end{axis}
\end{tikzpicture}
\end{document}

Is there an option to force re-reading the data for each table command?

result

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I don't think you can use skip first n key to filter the coordinates in a flexible fashion as it is a pgfplotstable key for either reading the table or typesetting it. Instead you can use filters to eliminate the odd/even numbered rows

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{filecontents}{data.dat}
1 1
2 4
3 3
4 8
\end{filecontents}
\begin{document}


\begin{tikzpicture}
    \begin{axis}
        \addplot[no markers,each nth point=2] table {data.dat};

        \addplot[only marks,x filter/.code={
                    \ifodd\numexpr\coordindex+1\relax
                        \def\pgfmathresult{}
                    \fi}
                ] table {data.dat};
    \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Of course with this code you can cook up your own filters (by using Mod(,) etc.) so it is doable anyways.

share|improve this answer
    
Ok, I thought the point of the table keys was exactly this kind of filtering (like gnuplot's every <skip>:<start>:…), so it's just a side-effect? –  pascal Apr 13 '13 at 0:28
    
@pascal I think it's more of a row downsampling while reading, column creating and/or typesetting the data. As you can see you can introduce the same functionality (or maybe I don't know in case it already exists). I think this is also easy to introduce so you can file a feature request for that. –  percusse Apr 13 '13 at 0:42

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.