I have a group plot and when I try to add a legend it repeats on all subgraphs. I want a single common legend line at the top of the whole graph.
\documentclass{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size= 2 by 4},height=5cm,width=6.4cm,legend entries = {curve1,curve2,curve3}]
\nextgroupplot[title=type1,ylabel={Range1 },symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
\addplot[blue] table{Data/test.dat};
\addplot[red] table{Data/test1.dat};
\addplot[green] table{Data/test2.dat};
\coordinate (top) at (rel axis cs:0,1);% coordinate at top of the first plot
\nextgroupplot[title=type2,symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
\addplot[blue] table{Data/test.dat};
\addplot[red] table{Data/test1.dat};
\addplot[green] table{Data/test2.dat};
\nextgroupplot[ylabel={Range2 },symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
\addplot[blue] table{Data/test.dat};
\addplot[red] table{Data/test1.dat};
\addplot[green] table{Data/test2.dat};
\nextgroupplot[symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
\addplot[blue] table{Data/test.dat};
\addplot[red] table{Data/test1.dat};
\addplot[green] table{Data/test2.dat};
\nextgroupplot[ylabel={Range3 },symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
\addplot[blue] table{Data/test.dat};
\addplot[red] table{Data/test1.dat};
\addplot[green] table{Data/test2.dat};
\nextgroupplot[symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
\addplot[blue] table{Data/test.dat};
\addplot[red] table{Data/test1.dat};
\addplot[green] table{Data/test2.dat};
\nextgroupplot[xlabel={Number of Threads},ylabel={Range4 },symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
\addplot[blue] table{Data/test.dat};
\addplot[red] table{Data/test1.dat};
\addplot[green] table{Data/test2.dat};
\nextgroupplot[xlabel={Number of Threads},symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
\addplot[blue] table{Data/test.dat};
\addplot[red] table{Data/test1.dat};
\addplot[green] table{Data/test2.dat};
\coordinate (bot) at (rel axis cs:0,0);% coordinate at bottom of the last plot
\end{groupplot}
\path (top-|current bounding box.west)-- node[anchor=south,rotate=90] {Throughput} (bot-|current bounding box.west);
\end{tikzpicture}
\end{document}


Data/test.dat? How is it structured? – Mr.Epic Fail Jul 12 '22 at 14:59