Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In this group plot how do I add labels to individual graphs. I want to label each graph as (a), (b), (c)...

 \documentclass[margin=5mm]{standalone}
        \usepackage{pgfplots}
        \usetikzlibrary{matrix}
        \usepgfplotslibrary{groupplots}
        \pgfplotsset{compat=newest}
        \begin{document}

        \begin{tikzpicture}
                \begin{groupplot}[group style={group size= 2 by 4},height=5cm,width=6.4cm]
                        \nextgroupplot[title=type1,ylabel={Range1 }]
                                        \addplot[blue] {x};\label{plots:plot1}
                                        \addplot[red] {x^2};\label{plots:plot2}
                                        \addplot[green] {2*x};\label{plots:plot3}
                                        \coordinate (top) at (rel axis cs:0,1);% coordinate at top of the first plot
                        \nextgroupplot[title=type2]
                                        \addplot[blue]{x};
                        \nextgroupplot[ylabel={Range2 }]
                                        \addplot[blue]{x};
                        \nextgroupplot
                                        \addplot[blue]{x};
                        \nextgroupplot[ylabel={Range3 }]
                                        \addplot[blue]{x};
                        \nextgroupplot
                                        \addplot[blue]{x};
                        \nextgroupplot[xlabel={Number of Threads},ylabel={Range4 }]
                                        \addplot[blue]{x};
                        \nextgroupplot[xlabel={Number of Threads}]
                                        \addplot[blue]{x};
                                        \coordinate (bot) at (rel axis cs:1,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);
        % legend
        \path (top|-current bounding box.north)--
                    coordinate(legendpos)
                    (bot|-current bounding box.north);
        \matrix[
                matrix of nodes,
                anchor=south,
                draw,
                inner sep=0.2em,
                draw
            ]at([yshift=1ex]legendpos)
            {
                \ref{plots:plot1}& curve 1&[5pt]
                \ref{plots:plot2}& curve2&[5pt]
                \ref{plots:plot3}& curve 3\\};
        \end{tikzpicture}
        \end{document}

output: output

share|improve this question

1 Answer 1

up vote 6 down vote accepted

You can use group names key and with the help of positioninglibrary ad a node below every plot like:

\node[below = 0.5cm of my plots c1r1.south] {(a)};

Here c1r1 means column 1 and row 1.

 \documentclass[margin=5mm]{standalone}
        \usepackage{pgfplots}
        \usetikzlibrary{matrix,positioning}
        \usepgfplotslibrary{groupplots}
        \pgfplotsset{compat=newest}
        \begin{document}

        \begin{tikzpicture}
                \begin{groupplot}[group style={group name=my plots,group size= 2 by 4,vertical sep=1.5cm },height=5cm,width=6.4cm]
                        \nextgroupplot[title=type1,ylabel={Range1 }]
                                        \addplot[blue] {x};\label{plots:plot1}
                                        \addplot[red] {x^2};\label{plots:plot2}
                                        \addplot[green] {2*x};\label{plots:plot3}
                                        \coordinate (top) at (rel axis cs:0,1);% coordinate at top of the first plot
                        \nextgroupplot[title=type2]
                                        \addplot[blue]{x};
                        \nextgroupplot[ylabel={Range2 }]
                                        \addplot[blue]{x};
                        \nextgroupplot
                                        \addplot[blue]{x};
                        \nextgroupplot[ylabel={Range3 }]
                                        \addplot[blue]{x};
                        \nextgroupplot
                                        \addplot[blue]{x};
                        \nextgroupplot[xlabel={Number of Threads},ylabel={Range4 }]
                                        \addplot[blue]{x};
                        \nextgroupplot[xlabel={Number of Threads}]
                                        \addplot[blue]{x};
                                        \coordinate (bot) at (rel axis cs:1,0);% coordinate at bottom of the last plot
                \end{groupplot}
                \node[below = 0.5cm of my plots c1r1.south] {(a)};
                \node[below = 0.5cm of my plots c2r1.south] {(b)};
                \node[below = 0.5cm of my plots c1r2.south] {(c)};
                \node[below = 0.5cm of my plots c2r2.south] {(d)};
                \node[below = 0.5cm of my plots c1r3.south] {(e)};
                \node[below = 0.5cm of my plots c2r3.south] {(f)};
                \node[below = 0.9cm of my plots c1r4.south] {(g)};
                \node[below = 0.9cm of my plots c2r4.south] {(h)};
                \path (top-|current bounding box.west)--
                            node[anchor=south,rotate=90] {throughput}
                            (bot-|current bounding box.west);
        % legend
        \path (top|-current bounding box.north)--
                    coordinate(legendpos)
                    (bot|-current bounding box.north);
        \matrix[
                matrix of nodes,
                anchor=south,
                draw,
                inner sep=0.2em,
                draw
            ]at([yshift=1ex]legendpos)
            {
                \ref{plots:plot1}& curve 1&[5pt]
                \ref{plots:plot2}& curve2&[5pt]
                \ref{plots:plot3}& curve 3\\};
        \end{tikzpicture}
        \end{document}

enter image description here

You may have to adjust the vertical sep so as to accommodate these nodes like I did (1.5cm).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.