I am trying to filter points according to its x values. The data may be from a table-formatted text file, or directly typed in coordinates{...}. I tried to use x filter/.code, but for data from text file it seems fine, while the same code yield compiling error if the data are directly typed through coordinates{...}.
\addplot[scatter, only marks] table[x=xx, y=yy, col sep=comma]{tmp.txt};
% Seems working
vs
\addplot[scatter, only marks] coordinates{(0,0) (1,1) (1,1.5) (2,2)};
%|16 error| Missing = inserted for \ifnum. Y ...s] coordinates{(0,0) (1,1) (1,1.5) (2,2)};
I suspect it might be my problematic usage of \pgfmathresult in x filter, but not sure how to fix. The following are the MWE along with the compilation error. Assuming file tmp.txt is:
xx, yy
0,0
1,1
1,1.5
2,2
And the code is:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
x filter/.code= {
\ifnum\pgfmathresult=1
\def\pgfmathresult{}
\fi
}]
% This seems working fine
\addplot[scatter, only marks] table[x=xx, y=yy, col sep=comma]{tmp.txt};
% This cause compilation error, which is
% |16 error| Missing = inserted for \ifnum. Y ...s] coordinates{(0,0) (1,1) (1,1.5) (2,2)};
%\addplot[scatter, only marks] coordinates{(0,0) (1,1) (1,1.5) (2,2)};
\end{axis}
\end{tikzpicture}
\end{document}

