filter pgfplots data more than once (e.g. with discard if)
You can filter the data more than once by adapting the code (which was originally posted in an answer to Is it possible to change the color of a single bar when the bar plot is based on symbolic values? and Different color for individual bar in bar chart & adding bar labels) slightly, using x filter/.append code
instead of x filter/.code
:
For filtering on a symbolic column:
\pgfplotsset{
discard if/.style 2 args={
x filter/.append code={
\edef\tempa{\thisrow{#1}}
\edef\tempb{#2}
\ifx\tempa\tempb
\def\pgfmathresult{inf}
\fi
}
},
discard if not/.style 2 args={
x filter/.append code={
\edef\tempa{\thisrow{#1}}
\edef\tempb{#2}
\ifx\tempa\tempb
\else
\def\pgfmathresult{inf}
\fi
}
}
}
For filtering on a numerical column:
\pgfplotsset{
discard if/.style 2 args={
x filter/.append code={
\ifdim\thisrow{#1} pt=#2pt
\def\pgfmathresult{inf}
\fi
}
},
discard if not/.style 2 args={
x filter/.append code={
\ifdim\thisrow{#1} pt=#2pt
\else
\def\pgfmathresult{inf}
\fi
}
}
}