\documentclass[crop,tikz]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepgfplotslibrary{groupplots}

\input{setup.tex}
\usepgfplotslibrary{fillbetween}

\begin{document}
\pgfplotsset{
acc axis/.style={
	xmin=0,xmax=8000,
	ymin=0.8,ymax=1,
	legend style={ at={(0.9,0.1)}, anchor=south east },
	xlabel={Epoch},
	ylabel={Accuracy},
  ymajorgrids=true,
  xtick={0,2000,4000,6000},
},
}

\newcommand{\addaccplot}[1]{
  \pgfplotstableread[col sep=comma]{accuracy/SYN-ReLU/#1/accuracy.csv}\accA
	% Train
	\addplot[color=colTrain] table[x=epoch,y=train_mean]{\accA};
	\addplot[name path=tanh_up, color=colTrain!40] table[x=epoch,y=train_up]{\accA};
	\addplot[name path=tanh_lw, color=colTrain!40] table[x=epoch,y=train_lw]{\accA};
	\addplot[colTrain!40,fill opacity=0.4] fill between[of=tanh_up and tanh_lw];
	% Test
	\addplot[color=colTest,dashed] table[x=epoch,y=test_mean]{\accA};
	\addplot[name path=tanh_up2, color=colTest!40] table[x=epoch,y=test_up]{\accA};
	\addplot[name path=tanh_lw2, color=colTest!40] table[x=epoch,y=test_lw]{\accA};
	\addplot[colTest!40,fill opacity=0.4] fill between[of=tanh_up2 and tanh_lw2];
}

\begin{tikzpicture}
	\begin{groupplot}[group style={group size= 4 by 1, horizontal sep=0cm,vertical sep=0cm}]
	  \nextgroupplot[acc axis,title=4 bits]
    \addaccplot{4}
    \nextgroupplot[acc axis,title=8 bits,IB noY]
    \addaccplot{8}
    \nextgroupplot[acc axis,title=32 bits,IB noY]
    \addaccplot{32}
    \nextgroupplot[
      acc axis,
      title=Non-quantized,
      IB noY,
      legend style={at={(0.85,0.1)}},
      xtick={0,2000,4000,6000,8000}
    ]
		% Legend
		\addlegendimage{no markers,colTrain}
		\addlegendentry{Train}
		\addlegendimage{no markers,dashed,colTest}
		\addlegendentry{Test}
    \addaccplot{bin}
	\end{groupplot}
\end{tikzpicture}
\end{document}
