1

I have data, that contains three columns: time, x, y. Now, I want to plot the data in the x-y plane like this:

\addplot[] table[x expr={\thisrowno{1}}, y expr={\thisrowno{2}}] {test.csv};

But furthermore, I only want to plot the data where the time fulfils certain conditions, e.g. only plot the first 300ns.

1

It took me some time to scrape together the answer, so I wanted to share it here. This can be achieved by using

\addplot[x filter/.expression={\thisrowno{0} <= 300e-9 ? nan : x}] table[x expr={\thisrowno{1}}, y expr={\thisrowno{2}}] test.csv};

(using an example from the coordfiltering lib)

Note how returning the nan for the x discards the whole datapoint.

More along the lines of this post pgfplots: plot from csv file starting at a specified row (which did not work at all for me) one can also write it as

\pgfplotsset{
    discard if larger/.style n args={2}{
        x filter/.expression={
            \thisrowno{#1} < #2 ? nan : x
        }
    },
    discard if smaller/.style n args={2}{
        x filter/.expression={
            \thisrowno{#1} > #2 ? nan : x
        }
    }
}

and then

\addplot[discard if larger={0}{300e-9}] table[x expr={\thisrowno{1}}, y expr={\thisrowno{2}}] test.csv};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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