2

I am trying to increase the size of the legend such that it exactly fits to size of the plot. But even after having a look at the PGF manual I could not figure out how I can realise my plan. Afterwards I want to equally distribute the legend entries within the box.

UPDATE

The actual solution was:

\def\WIDTH{7cm}
\def\INNERSEP{3pt}

\begin{axis}[
    xmin=1, xmax=10, xtick={1,...,10}, xmajorgrids=true, xlabel={Cores},
    ymin=0, ymax=100, ymajorgrids=true, ylabel={MFLUPS/s},
    scale only axis,  % <==== !!!!!!!
    extra description/.code={
        \node[
        draw,
        text depth=0pt,
        at={(current bounding box.north-|current axis.north)},
        anchor=south,
        text width=\WIDTH-2*\INNERSEP,
        inner sep=\INNERSEP,
        outer sep=0pt,
        ] {
    \hbox to \linewidth{%
        \hfill \ref{A} A \hfill \ref{B_B} B \hfill
        }%
    };
},
]   

ExamplePlot

\documentclass{standalone}

\usepackage{tikz}

\usepackage{pgfplots}
\pgfplotsset{compat = newest}

\begin{document}
\pgfplotsset{width=7cm}
\begin{tikzpicture}

\begin{axis}[
    xmin=1, xmax=10, xtick={1,...,10}, xmajorgrids=true, xlabel={Cores},
    ymin=0, ymax=100, ymajorgrids=true, ylabel={MFLUPS/s},
    legend style={
        at={(current bounding box.north-|current axis.north)},
        anchor=south,
        legend columns=-1,
        outer sep=0
    }]
\addplot [mark=square*, mark options={solid}, thick] table {
1   10
2   20
3   30
4   40
5   50
6   65
7   70
8   80
9   90
10  95
};
\addlegendentry{Graph A}
\addplot [mark=*, mark options={solid}, thick] table {
1   10
2   20
3   25
4   40
5   25
6   65
7   70
8   25
9   90
10  95
};
\addlegendentry{Graph B}
\end{axis}
\end{tikzpicture}
\end{document}
arox
  • 65
  • 7
  • @hooy, I agree, this looks very much like a duplicate. Do you want to flag the question as duplicate? – Stefan Pinnow Feb 09 '16 at 18:19
  • It does look like a solution to my problem... I'll give it a try. – arox Feb 09 '16 at 18:21
  • @StefanPinnow I already did, my above comment is an auto-comment that gets posted when raising that flag after having clicked "add a comment". But there is nothing stopping you from doing it either, if that's what you were wondering. Feel free. – sodd Feb 09 '16 at 18:22
  • @hooy, I think one time flagging is perfectly fine. And because also arox seems beeing convinced that it is a duplicate, there should not be a problem ;) – Stefan Pinnow Feb 09 '16 at 18:36
  • Thanks for giving the hint. I edited the question in order to emphasize the required changes to solve my problem. – arox Feb 09 '16 at 19:04

0 Answers0