I have a table with data from a file and before anything, I sort the data. Then I would like to filter only the rows that have a specific value. There has been a similar question which almost contains the answer to my question:
Selecting rows to be displayed with pgfplotstable
In addition to that I would like to know how to plot the filtered data.
Here is an example:
\documentclass{minimal}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\begin{document}
\pgfplotstableread{
T A B C
20 0 450 43
23 0 400 42
25 0 350 41
30 0 320 40
40 0 300 40
20 10 400 38
23 10 380 37
25 10 350 36
30 10 310 35
40 10 280 34
}\data
\pgfplotstablesort[sort key={T}]{\sorted}{\data} %get the data and sort by column 'T'
%select data in column 'T' that complies with a certain value and write the table
\pgfplotstabletypeset[row predicate/.code={%
\pgfplotstablegetelem{#1}{T}\of{\sorted}
\ifnum\pgfplotsretval=20\relax
\else\pgfplotstableuserowfalse\fi}]
{\sorted}
\begin{tikzpicture}
\begin{axis}[
xlabel=A,
ylabel=B]
\addplot table[
x=A,
y=B]
{\filtered}; %here the filtered data from above needs to be addressed, how to do that?
\end{axis}
\end{tikzpicture}
\end{document}
What I don't know is how to address the filtered data above to plot it. I thought it might work by generating a table named \filtered.

[x=A,y=B]options toaddplotinstead oftable. I'll fix it in a sec. – percusse Aug 07 '12 at 13:49pgfmathparseto do the comparison, you can use\ifdim\pgfplotsretval pt=20.256ptin place of\ifnum\pgfplotsretval=20(so you just addptto turn the values into lengths). – Jake Aug 10 '12 at 06:24ptis quite nice. It works for the plotting of the diagram. I tried to use this for the plotting of the table too, but there I failed. – wonder Aug 10 '12 at 07:36\ifnum\pgfplotsretval=20with\ifdim\pgfplotsretval pt=20.256pt\relax). What error message do you get? – Jake Aug 10 '12 at 08:06\pgfmathparsestep. I'm not sure whether there's any difference in precision (if anything, I would guess that your approach is more precise), but the\ifdimapproach uses less lines and is (in my opinion) a little more readable. – Jake Aug 10 '12 at 08:39pgfplotstabletypeset. – Jake Aug 10 '12 at 09:11pgfplotstabletypesetbut it did not filter correctly. But it returned no error message as well. I used it as:\pgfplotstabletypeset[row predicate/.code={% \pgfplotstablegetelem{#1}{T}\of{\sorted} \pgfmathtruncatemacro{\tempva}{abs(\pgfplotsretval - 0.567641034) == 0 ? 1: 0} \ifnum\tempva>0%true \else%false \def\pgfmathresult{} \fi }, ]{\sorted}I don't know where the error is. – wonder Aug 10 '12 at 09:40nan. I even want to filter by two columns. From the table I first want to filter by columnLand than by columnC. Then I want to plot the table sorted by columnTand a diagram withTand one of the columnsDorVaccording to the table (see the next following comment). – wonder Aug 10 '12 at 10:48L C T D V<br> A 0 20 1.00346 205<br> A 0 23 1.00118 177<br> A 0 25 0.99964 155<br> A 0 30 0.99579 115<br> A 0 40 0.98807 69.5<br> A 9.2 20 0.98444 nan<br> A 9.2 30 0.97664 66<br> A 9.2 40 0.96862 43<br> A 30 20 0.96936 nan<br> A 30 23 0.96622 16.1<br> A 30 30 0.964 15.3<br> B 0 20 1.05104 535<br> B 0 23 1.04876 439<br> B 0 25 1.0472 373<br> B 0 30 1.04327 234<br> B 0 40 1.03555 115<br> B 9.6 20 1.02981 nan<br> B 9.6 23 1.02749 152<br> B 9.6 25 1.0259 134– wonder Aug 10 '12 at 10:48<br>as a row-separator but it didn't work like I expected. – wonder Aug 10 '12 at 10:55