I am using pgfplots to make plots for my thesis, and I have many scatter plots that I want to have consistent formatting. I am controlling the shape and color of the scatter plot marks with two columns (from external files loaded through \pgfplotstableread) that have consistent names across the many input files.
So far, my solution is to use one as to define scatter/classes and to use the other to filter. This has worked fine, but I would like to have the filter parameters specified as a style, rather than needing to repeat the filter code on every \addplot command.
What is working:
\documentclass{article}
\usepackage{pgfplots,pgfplotstable,tikz}
\usepackage{filecontents}
\begin{filecontents}{data.dat}
x y color shape
1 3 a 0
2 6 b 0
3 5 a 1
4 4 b 1
5 9 a 0
6 1 b 1
\end{filecontents}
\begin{document}
\pgfplotstableread{data.dat}\datafile
\begin{tikzpicture}
\begin{axis}
\addplot[x filter/.code={
\pgfplotstablegetelem{\coordindex}{shape}\of{\datafile}
\ifnum\pgfplotsretval=0
\else
\def\pgfmathresult{}
\fi},only marks, scatter, scatter src=explicit symbolic, scatter/classes={
a={blue},%
b={red}%
},mark=o] table[x=x,y=y, meta=color] {\datafile};
\addplot[x filter/.code={
\pgfplotstablegetelem{\coordindex}{shape}\of{\datafile}
\ifnum\pgfplotsretval=1
\else
\def\pgfmathresult{}
\fi},only marks, scatter, scatter src=explicit symbolic, scatter/classes={
a={blue},%
b={red}%
},mark=square] table[x=x,y=y, meta=color] {\datafile};
\end{axis}
\end{tikzpicture}
\end{document}
I can't just plug the x filter code as it is into a style, since it uses the name of the table (which changes). I've tried the discard if not style, but it doesn't work with \pgfplotstableread
Can I put the filtering code in a style and modify it so it automatically gets the correct table (being used for everything else in the plot)?
I'm aware that I could approach the entire problem differently by using \pgfplotstableset to create a new column in the table that has (somehow) concatenated the color and shape, and then have (2x2 in the example) 4 different scatter classes.
