As everyone knows from this answer, it is possible to filter rows from a table using discard if not
style/filter. But this solution works only if one provides a filename as the argument to \addplot table
, and it won't work if one read the table using \pgfplotstableread{file}\name
and use it as the argument \addplot[discard if not...] table \name;
:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}
\usepackage{filecontents}
\begin{filecontents}{fulltable.dat}
houses instance value
20 1 8919
20 2 8965
20 3 8901
20 4 8816
20 5 8875
20 6 9027
20 7 8915
20 8 8907
20 9 8832
20 10 8934
200 1 84714
200 3 85630
200 4 84748
200 5 84565
200 6 85109
200 7 84588
200 8 84638
200 9 84673
200 10 85170
\end{filecontents}
\begin{document}
\pgfplotsset{
discard if not/.style 2 args={
x filter/.code={
\edef\tempa{\thisrow{#1}}
\edef\tempb{#2}
\ifx\tempa\tempb
\else
\def\pgfmathresult{inf}
\fi
}
}
}
\pgfplotstableread{fulltable.dat}\fulltable
\begin{tikzpicture}[trim axis left]
\begin{axis}[
title={{\bfseries Plot for 20 houses instances}},
xlabel={Instance},
ylabel={Value}]
\addplot+[only marks, discard if not={houses}{20}] table[x=instance, y=value]
{fulltable.dat};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[trim axis left]
\begin{axis}[
title={{\bfseries Plot for 20 houses instances}},
xlabel={Instance},
ylabel={Value}]
\addplot+[only marks, discard if not={houses}{20}] table[x=instance, y=value]
{\fulltable};
\end{axis}
\end{tikzpicture}
\end{document}
What to do? I want this thing working for macros.