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.
Best Answer
You can use the
x filter/.code={}
instructions (thanks to Jake for spotting a mistake)If the entries of the table involves nonintegers then
\ifnum
would complain hence it needs another step.which leads to the same output above. I have modified a table entry as it is almost passing the test if lowered slightly. So you should be careful about the numerical precision.