# plotting data with two conditions

I can plot data depending on the value in one column like this:

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{filecontents}{data.csv}
a,b,c,d
0,0,1,2
2,2,1,2
3,-3,1,3
2,1,2,4
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}
table[x=a, y=b, col sep=comma,
restrict expr to domain={\thisrow{c}}{1:1}]{data.csv};
\end{axis}
\end{tikzpicture}
\end{document}


Is it possible to apply two conditions? For example, I would like to plot data where both the value in c = 1 and the value in d = 2 without plotting data where only one applies.

You can use x expr to apply the conditions. If the result is not true, set the x value to nan:

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{filecontents}{data.csv}
a,b,c,d
0,0,1,2
2,2,1,2
3,-3,1,3
2,1,2,4
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}

• Perfect. And for anyone wanting three conditions, this seems to work: x expr={and(\thisrow{c}==1,and(\thisrow{a}==0,\thisrow{d}==2))==1?\thisrow{a}:nan}, Jan 28 '18 at 9:44