# How to plot data from multiple filters using 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.

-
I freely admit knowing nothing about tikz and pgfplots, but could you be more specific on what you mean by "filters". Are you trying to process a block of numbers, or are you talking about image transparancies, etc.? –  Steven B. Segletes Mar 30 '13 at 20:32
@StevenB.Segletes Sorry that I didn't provide any code but I'm completely unsure about how to achieve what I described, but the referenced question gives an example ob the filter I want to apply on the input data (numbers) before plotting the results of all filters in one axis-environment. –  soriak Mar 30 '13 at 20:36
OK, so you want to filter the data. The answer will depend on whether you want, as the referenced question said, to only plot lines with a particular number. Other filters might be plot every nth line. Others might be to extract column 3 from the file. Each answer might involve different tools. The readarray package will read a data file and stick each data element into a separate variable, so that you could recall cell 4,3 with \Arrayij{4}{3}. That might help you filter. If you need to take a cell's data and process it, like removing decimal points, stringstrings package might help. –  Steven B. Segletes Mar 30 '13 at 20:52
@StevenB.Segletes I want to plot multiple groups of lines each group with a particular number. I will add an example of the data I try to plot to my question, sorry that I didn't give an example data. –  soriak Mar 30 '13 at 21:02

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{
x filter/.code={
\edef\tempa{\thisrow{#1}}
\edef\tempb{#2}
\ifx\tempa\tempb
\else
\def\pgfmathresult{inf}
\fi
}
}
}

\begin{document}
\begin{tikzpicture}
\begin{axis}

thanks for your answer. I got a problem applying your solution. It turn out that the \else is always executed. It occurred to me that the headers in the solution you referred to are given in brackets {} but adding these to my data didn't solve the problem. –  soriak Mar 30 '13 at 23:43
I didn't read your answer to the other question carefully enough. The problem was that I did supply a table instead of a datafile to \addplot –  soriak Mar 31 '13 at 6:28