4

How can I create a single legend entry for 4 plots at the bottom of the group of plots?. Something like this:

    Title                        Title
--------------             ----------------
-            -             -              -
-            -             -              -
-            -             -              -
-            -             -              -
--------------             ----------------


    Title                       Title
--------------             ----------------
-            -             -              -
-            -             -              -
-            -             -              -
-            -             -              -
--------------             ----------------


          -------------------
           ---- line
           ---- line2
           ---- line3
           ---- line4
          -------------------

     Figure 1. A caption 

This is the code from a previous question:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name=my plots,
group size=2 by 2,
xlabels at=edge bottom,
ylabels at=edge left,
horizontal sep=2cm,vertical sep=3cm,
},
legend style={at={(.5,0.9)},anchor=north east},
symbolic x coords={Hamming loss, Accuracy, F1-score, Score, Recall, Precision, Jaccard similarity, F-Beta score}, xtick=data,
x tick label style={rotate=45,anchor=east},
width=0.5\linewidth
]
\nextgroupplot


\addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};

\nextgroupplot


\addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};


%Sistema para un kernel lineal:


\nextgroupplot


\addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};

\addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};


\nextgroupplot

%bolita
\addlegendentry{text1}
\addplot[mark=*,thick,blue] coordinates {(Hamming loss,55.36) (Accuracy,44.63) (F1-score,27.55) (Score,46.63) (Recall,44.63) (Precision, 19.26) (Jaccard similarity, 44.63) (F-Beta score,10.03)};

%rombo
\addlegendentry{text1 + text2}
\addplot[mark=diamond*,thick,red] coordinates{(Hamming loss,55.12) (Accuracy,44.87) (F1-score,27.80) (Score,46.65) (Recall,45.0) (Precision, 20.20) (Jaccard similarity, 44.87) (F-Beta score,10.00)};

%linea punteada
\addlegendentry{text1 + text2 + text3}
\addplot[mark=o,mark options={solid},black,thick,dashed] coordinates {(Hamming loss,54.89) (Accuracy, 45.10) (F1-score,28.04) (Score,46.14) (Recall,45.0) (Precision, 20.34) (Jaccard similarity, 45.10) (F-Beta score,10.20)};


\addlegendentry{text1 + text2 + text3 + text4}
\addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};



\end{groupplot}
\end{tikzpicture}
\end{document}

The problem with this is that the legend entries are overlying one each other, also how can I increase the size of all the plots in order to see what happened in a better way?. Thanks in advance for the help guys!

1 Answers1

5

this is what john kormylo was referring to; i essentially used a verbatim copy/paste of your code (so the python programmer in me wants to have an mi because of the indentation):

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{groupplot}[
group style={
    group name=my plots,
    group size=2 by 2,
    xlabels at=edge bottom,
    ylabels at=edge left,
    horizontal sep=2cm,vertical sep=3cm,},
legend style={at={(.5,0.9)},anchor=north east},
symbolic x coords={Hamming loss, Accuracy, F1-score, Score, Recall, Precision, Jaccard similarity, F-Beta score}, xtick=data,
x tick label style={rotate=45,anchor=east},
width=0.5\linewidth
]
\nextgroupplot

\addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};

\nextgroupplot

\addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};

%Sistema para un kernel lineal:

\nextgroupplot

\addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};

\addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};

\nextgroupplot[legend to name=testLegend]

%bolita
\addlegendentry{text1}
\addplot[mark=*,thick,blue] coordinates {(Hamming loss,55.36) (Accuracy,44.63) (F1-score,27.55) (Score,46.63) (Recall,44.63) (Precision, 19.26) (Jaccard similarity, 44.63) (F-Beta score,10.03)};

%rombo
\addlegendentry{text1 + text2}
\addplot[mark=diamond*,thick,red] coordinates{(Hamming loss,55.12) (Accuracy,44.87) (F1-score,27.80) (Score,46.65) (Recall,45.0) (Precision, 20.20) (Jaccard similarity, 44.87) (F-Beta score,10.00)};

%linea punteada
\addlegendentry{text1 + text2 + text3}
\addplot[mark=o,mark options={solid},black,thick,dashed] coordinates {(Hamming loss,54.89) (Accuracy, 45.10) (F1-score,28.04) (Score,46.14) (Recall,45.0) (Precision, 20.34) (Jaccard similarity, 45.10) (F-Beta score,10.20)};

\addlegendentry{text1 + text2 + text3 + text4}
\addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};



\end{groupplot}
\end{tikzpicture}
\ref{testLegend}
\end{center}
\end{document}

that will at least get you a legend at the bottom like i think you want: legendToName

but i'm not exactly sure if that's what you want, and i think you asked something else about size but i have no idea what you mean by that, so feel free to clarify...

edit:

for this i'm assuming you want to glance at the plots in a slightly larger form so you can see if they came out correctly or something like that. i don't have any additional requirements so all i did was change how much space you're telling pgfplots it has to work with. i also cleaned it up a tiny bit:

\documentclass{article}
    \usepackage{fullpage}
    \usepackage{pgfplots}
    \usepgfplotslibrary{groupplots}
    \pgfplotsset{compat=1.12}
    \begin{document}

    \begin{center}
        \begin{tikzpicture}
            \begin{groupplot}[
                group style={
                    group name=my plots,
                    group size=2 by 2,
                    xlabels at=edge bottom,
                    ylabels at=edge left,
                    horizontal sep=2cm,
                    vertical sep=3cm,
                    },
                symbolic x coords={Hamming loss, Accuracy, F1-score, Score, Recall, Precision, Jaccard similarity, F-Beta score}, 
                xtick=data,
                x tick label style={rotate=45,anchor=east},
                width=0.5\linewidth
            ]
                \nextgroupplot
                    \addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};
                \nextgroupplot
                    \addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};
                %Sistema para un kernel lineal:
                \nextgroupplot
                    \addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};
                    \addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};
                \nextgroupplot[legend to name=testLegend]
                    %bolita
                    \addlegendentry{text1}
                    \addplot[mark=*,thick,blue] coordinates {(Hamming loss,55.36) (Accuracy,44.63) (F1-score,27.55) (Score,46.63) (Recall,44.63) (Precision, 19.26) (Jaccard similarity, 44.63) (F-Beta score,10.03)};
                    %rombo
                    \addlegendentry{text1 + text2}
                    \addplot[mark=diamond*,thick,red] coordinates{(Hamming loss,55.12) (Accuracy,44.87) (F1-score,27.80) (Score,46.65) (Recall,45.0) (Precision, 20.20) (Jaccard similarity, 44.87) (F-Beta score,10.00)};
                    %linea punteada
                    \addlegendentry{text1 + text2 + text3}
                    \addplot[mark=o,mark options={solid},black,thick,dashed] coordinates {(Hamming loss,54.89) (Accuracy, 45.10) (F1-score,28.04) (Score,46.14) (Recall,45.0) (Precision, 20.34) (Jaccard similarity, 45.10) (F-Beta score,10.20)};
                    \addlegendentry{text1 + text2 + text3 + text4}
                    \addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};
            \end{groupplot}
        \end{tikzpicture}
        \ref{testLegend}
    \end{center}

\end{document}

i won't include an image since it looks very much the same, just larger in relation to the page. you don't need the legend style specification any longer. i opened the margins up a bit with \usepackage{fullpage} and that gives pgflots a little more room to work with. i presume you know that you're specifying the size of the plots yourself by including width=0.5\linewidth so the plots will get bigger if you change that to width=0.6\linewidth or something like that. i didn't add that since that will do unspeakable things to the margins and require a lot more fiddling.

edit again:

i added ymax= and ymin= as you requested...

\documentclass{article}
    \usepackage{fullpage}
    \usepackage{pgfplots}
    \usepgfplotslibrary{groupplots}
    \pgfplotsset{compat=1.12}
    \begin{document}

    \begin{center}
        \begin{tikzpicture}
            \begin{groupplot}[
                group style={
                    group name=my plots,
                    group size=2 by 2,
                    xlabels at=edge bottom,
                    ylabels at=edge left,
                    horizontal sep=2cm,
                    vertical sep=3cm,
                    },
                symbolic x coords={Hamming loss, Accuracy, F1-score, Score, Recall, Precision, Jaccard similarity, F-Beta score}, 
                xtick=data,
                x tick label style={rotate=45,anchor=east},
                ymax=100,
                ymin=10,
                width=0.5\linewidth
            ]
                \nextgroupplot
                    \addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};
                \nextgroupplot
                    \addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};
                %Sistema para un kernel lineal:
                \nextgroupplot
                    \addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};
                    \addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};
                \nextgroupplot[legend to name=testLegend]
                    %bolita
                    \addlegendentry{text1}
                    \addplot[mark=*,thick,blue] coordinates {(Hamming loss,55.36) (Accuracy,44.63) (F1-score,27.55) (Score,46.63) (Recall,44.63) (Precision, 19.26) (Jaccard similarity, 44.63) (F-Beta score,10.03)};
                    %rombo
                    \addlegendentry{text1 + text2}
                    \addplot[mark=diamond*,thick,red] coordinates{(Hamming loss,55.12) (Accuracy,44.87) (F1-score,27.80) (Score,46.65) (Recall,45.0) (Precision, 20.20) (Jaccard similarity, 44.87) (F-Beta score,10.00)};
                    %linea punteada
                    \addlegendentry{text1 + text2 + text3}
                    \addplot[mark=o,mark options={solid},black,thick,dashed] coordinates {(Hamming loss,54.89) (Accuracy, 45.10) (F1-score,28.04) (Score,46.14) (Recall,45.0) (Precision, 20.34) (Jaccard similarity, 45.10) (F-Beta score,10.20)};
                    \addlegendentry{text1 + text2 + text3 + text4}
                    \addplot[mark=diamond*,thick,yellow] coordinates{(Hamming loss,52.44) (Accuracy, 47.55) (F1-score,30.64) (Score,44.94) (Recall,47.55) (Precision, 22.61) (Jaccard similarity, 47.55) (F-Beta score,10.62)};
            \end{groupplot}
        \end{tikzpicture}
        \ref{testLegend}
    \end{center}

\end{document}

...which produces:

tenToOneHundred

honestly though, i would change ymin=10 to something higher so that your last points aren't falling off the chart. pgfplots makes the plot bounds larger than your data range for pretty good reasons, imho.

aeroNotAuto
  • 2,390
  • Thanks for the help, I would like at the y axis go from 10 to 100 (change the scale in order to see better the results). – tumbleweed Apr 08 '15 at 01:50
  • I also tried to add a subtitle for each plot as follows: \nextgroupplot[title=One] but the box overlies with the plots, any idea of how to fix this?. – tumbleweed Apr 08 '15 at 03:36
  • 1
    @ml_guy i'm not exactly sure what sort of output you're seeing, and i want to ask you to post an image, but this page is getting super long. can you post your subtitle issue in a separate question, assuming it's not already answered on this site? – aeroNotAuto Apr 08 '15 at 03:42
  • 1
    @ml_guy i'm referring to questions like here and here for example. – aeroNotAuto Apr 08 '15 at 03:46
  • Thanks for the help @aeroNotAuto. I edited the question with the desired output and I tried both aproaches but that you mention. The second one works but its to close to the plot. Any idea of how to reach the edited desired output?. Thanks in advance – tumbleweed Apr 08 '15 at 03:59
  • 1
    @ml_guy i'd be happy to look at the titles issue, but please post a new question for it. as you can see, this one is already generating the automatic warnings. – aeroNotAuto Apr 08 '15 at 10:38
  • Can someone please explain the semantics of "legend to name=testLegend", "\addlegendentry", and "\ref{testLegend}"? The example above only uses \addlegendentry on the very last plotgroup. It is rarely the case that the last plotgroup contains the union of all the curves of the other groups. I'd like to use \addlegendentry in any or all plot groups, but still have only one legend displayed; that legend should display all the texts of all the \addlegendentry calls. It's not clear how to do this. – Jim Newton Jul 30 '18 at 09:56