I am trying to understand the following code:
\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
}
}
}
Here is my understanding after reading the manual:
\pgfplotssetis used to set document-wise style.discard if not/.style 2 argsdefines a style nameddiscard if notin the namespace/pgfplotsand takes two arguments:#1and#2.x filter/.codeis used to change the behavior of the PGFPLOTS regarding coordinate filtering. Here, we are saying to usex filterfor coordinate filtering based on a single coordinate..codeis similar to TeX command:\newcommand.x filtergets an input coordinate as#1and applies filtering and finally writes the results into the macro\pgfmathresult. If we set\pgfmathresulttoinfby\pgfmathresults{inf}this means the coordinate can be discarded (ifunbounded coords=discardis set).\thisrow{#1}returns the active row in#1column. In other words,\thisrow{#1}= table(active row,column=#1).\tempa{\thisrow{#1}}defines a macro namedtempawhich has a value of the currently active table row in the designated column,\tempa= table(active row,column=#1).\edefrefers to expanded definition. It expands the macro to evaluate its value.\edef\tempa{\thisrow{#1}}evaluate the macro and assigns the value of the active row in the designated column totempa.\edef\tempb{#2}assigns the value of the second argument to macrotempb.\ifx: I couldn't find this in the manual but I am assuming that\ifx\tempa\tempbis equivalent to logical condition:\tempa == \tempb. Maybe we have\ify?\pgfmathresult{inf}: up to this moment\pgfmathresulthas the value of the x coordinate and setting it toinfdiscards the coordinate ifunbounded coords=discardhas been set.\def\pgfmathresult{inf}I couldn't find what exactly\defdoes but I assume it sets the value of\pgfmathresulttoinfwhich can refer to discarding.
So, discard if not is a name of a style that when is called applies a coordinate discarding based on two input arguments.
I would be thankful if someone could correct me if I have not understood it correctly or give me a better interpretation.