[Tex/LaTex] Put legend (pgfplots) below the plot

legendpgfplots

I have a pgfplot where the legend is right to the plot. I create the plot as follows:

\begin{axis}[
    scale only axis,
    xmode=log,
    ymode=log,
    width=7cm,
    legend cell align=left,
    legend pos=outer north east,
    legend style={draw=none}
  ]

Now I would like to move the legend down below the plot. So I thought I have just to replace legend pos=outer north east by legend pos=outer south west. But LaTex does not like this idea: Choice 'outer south west' unknown in key '/pgfplots/le
gend pos'
. Whats wrong with this?

Best Answer

From section 4.8.5 of the manual, you can use every axis legend:

\pgfplotsset{every axis legend/.append style={
at={(0,0)},
anchor=north east}} 

Code: (partially from manual )

\documentclass{standalone}
\usepackage{pgfplots}
 \pgfplotsset{width=7cm,compat=1.7}
 \pgfplotsset{every axis legend/.append style={
    at={(0,0)},
    anchor=north east}}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(0,1) (1,2)};
\addplot coordinates {(0,2) (1,3)};
\legend{$l_1$,$l_2$,$l_3$}
\end{axis}
\end{tikzpicture}
\end{document}

Instead of the /.append style, it is possible to use legend style as in the following example. It has the same effect.

\documentclass{standalone}
\usepackage{pgfplots}
 \pgfplotsset{width=7cm,compat=1.7}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={
at={(0,0)},
anchor=north east}]
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(0,1) (1,2)};
\addplot coordinates {(0,2) (1,3)};
\legend{$l_1$,$l_2$,$l_3$}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

As percusse mentioned in comment, you can fine tune the position by at={(axis description cs:0,-0.1)} as in:

\documentclass{standalone}
\usepackage{pgfplots}
 \pgfplotsset{width=7cm,compat=1.7}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={
at={(0,0)},
anchor=north east,at={(axis description cs:0,-0.1)}}]
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(0,1) (1,2)};
\addplot coordinates {(0,2) (1,3)};
\legend{$l_1$,$l_2$,$l_3$}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here