Menu

#30 [groupplots] Legend entries from different plots

unassigned
open
groupplots (6)
5
2016-11-01
2012-06-20
Joe Sapp
No

I would like to place a legend outside an axis using symbols from multiple plots within a groupplot. Each of these plots shows some different data, so I'd like to use different symbols, colors, etc. in each plot. It currently doesn't seem to work (see http://tex.stackexchange.com/q/58719/9428\), so I'd like to request the feature be added. A simple example follows:

\documentclass[crop]{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{pgfplots}
    \usepgfplotslibrary{groupplots}
\begin{document}
    \begin{tikzpicture}
    \begin{groupplot}[
        group style={
            group size=2 by 2
        },
        legend to name=grouplegend,
    ]
    \nextgroupplot[title=One]
        \addplot+[color=Blue] coordinates {(0,0) (1,1) (2,2)};
            \addlegendentry{A}
    \nextgroupplot[title=Two]
        \addplot+[color=Red] coordinates {(0,2) (1,1) (2,0)};
            \addlegendentry{B}
    \nextgroupplot[title=Three]
        \addplot+[color=Gray] coordinates {(0,2) (1,1) (2,1)};
            \addlegendentry{C}
    \nextgroupplot[title=Four]
        \addplot+[color=Orange] coordinates {(0,2) (1,1) (1,0)};
            \addlegendentry{D}
    \end{groupplot}
    \node [below, yshift=-2\pgfkeysvalueof{/pgfplots/every axis title shift}]
        (l1) at ($(group c1r2.south)!0.5!(group c2r2.south)$) {\ref{grouplegend}};
    \end{tikzpicture}
\end{document}

Discussion

  • xenocrates87

    xenocrates87 - 2015-01-25

    I would also like a solution to this problem. It should be relatively easy to implement? Perhaps with an option for legend entries to handle it?

     
    • Christian Feuersänger

      Thanks for the update. I will consider it for one of the next releases.

       

      Last edit: Stefan Pinnow 2017-06-05