[Tex/LaTex] How to plot data from multiple filters using pgfplots

pgfplots

I'm searching for a way to apply multiple filters to a data input and plot the result of each filter in one axis environment. I found the following question which applies one filter but uses the filter in an axis environment. Having multiple axis environment in a tikz picture ends up in weird results. Any idea how to achieve that for multiple filters/plots.

EDIT:
here an example:

P X Y
0 1 0.882352941176
0 2 11.0
0 3 11.0
0 4 6.0
0 5 3.0
0 6 1.0625
0 7 0.689655172414
0 8 0.541125541126
0 9 0.519576719577

1 1 1.13333333333
1 2 7.0
1 3 4.0
1 4 2.66666666667
1 5 1.2
1 6 0.594594594595
1 7 0.447368421053
1 8 0.423202614379
1 9 0.410808614384

I want to plot a parametrized plot For each P I want to create a line plot with X and Y values from the according X and Y column. I want to filter for each P and then plot all the results in one axis.
Sorry for providing this only after being asked for.

Best Answer

You can use the approach from Is it possible to change the color of a single bar when the bar plot is based on symbolic values? to filter the data in each of your \addplot commands:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}

\begin{filecontents}{data.dat}
P X Y
0 1 0.882352941176
0 2 11.0
0 3 11.0
0 4 6.0
0 5 3.0
0 6 1.0625
0 7 0.689655172414
0 8 0.541125541126
0 9 0.519576719577

1 1 1.13333333333
1 2 7.0
1 3 4.0
1 4 2.66666666667
1 5 1.2
1 6 0.594594594595
1 7 0.447368421053
1 8 0.423202614379
1 9 0.410808614384       
\end{filecontents}

\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
        }
    }
}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [ultra thick, black, discard if not={P}{0}] table [x=X, y=Y] {data.dat};
\addplot [ultra thick, red, discard if not={P}{1}] table [x=X, y=Y] {data.dat};
\end{axis}
\end{tikzpicture}
\end{document}