is there an easy way to check if a \addplot(+) table [...] command in PGFPLOTS has any drawn any points? The reason is that I want to process the data dynamically, and if the plot is empty, the legend should be omitted.
Here is a MWE:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfkeys{
/tr/rowfilter/.style 2 args={
/pgfplots/x filter/.append code={
\edef\arga{\thisrow{#1}}
\edef\argb{#2}
\ifx\arga\argb
\else
\def\pgfmathresult{}
\fi
}
}
}
\usepackage{filecontents}
\begin{filecontents}{diagram.dat}
x y kind
1 10 a
1 20 a
2 13 b
2 15 b
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[filter discard warning=false]
\addplot table[/tr/rowfilter={kind}{a},/tr/rowfilter={x}{2}] {diagram.dat}; % if the plot doesn't contain curve a,
\addlegendentry{curve a} % <- don't execute this line
\addplot table[/tr/rowfilter={kind}{b},/tr/rowfilter={x}{2}] {diagram.dat};
\addlegendentry{curve b}
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[filter discard warning=false]
\addplot table[/tr/rowfilter={kind}{a},/tr/rowfilter={x}{1}] {diagram.dat};
\addlegendentry{curve a}
\addplot table[/tr/rowfilter={kind}{b},/tr/rowfilter={x}{2}] {diagram.dat};
\addlegendentry{curve b}
\end{axis}
\end{tikzpicture}
\end{document}
In the first diagram the legend is wrong: the line belongs to dataset of curve b! I thought of something like \newif\ifplotexists, but, as there are two filters, how to decide if \plotexistsfalse or \plotexiststrue should be set?
