[Tex/LaTex] How to reposition the legend

legendtikz-pgf

Right now, it looks like this:

enter image description here

I don't like that the box intersects the function graph. How could you reposition it?

And I cannot see the label for the y-axis. Where has it gone? Could you also make the y-axis a little bit longer, so you can see the arrow of the y-axis completely?

The code looks like this:

\begin{figure}[!h]
\centering
\begin{tikzpicture}
\begin{axis}[
    axis lines = middle,
    xlabel = $x$,
    ylabel = {$f(x)$}
]

\addplot [
    domain=-20:20, 
    samples=100, 
    color=blue,
]
{sin(deg(x)) / deg(x)};
\addlegendentry{$si(x) = sin(x) / x$}
\end{axis}
\end{tikzpicture}
\caption{}
\end{figure}

Best Answer

enter image description here

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
    axis lines = middle,
    xlabel = $x$,
    ylabel = {$f(x)$},
    ymax=1.2,
    legend style={at={(0.65,.9)},anchor=north west},
]
\addplot [
    domain=-20:20,
    samples=200,
    color=blue,
]
{sin(deg(x)) / (x)};
\addlegendentry{$si(x) = sin(x) / x$}
\end{axis}
\end{tikzpicture}

\end{document}

The si(x) function should have a maximum of 1, so the function should read {sin(deg(x)) / (x)} instead of {sin(deg(x)) / deg(x)}. Also to enlarge the y-axis a bit we can add ymax=1.2,. For positioning the legend, we can adjust the position by the legend style legend style={at={(0.65,.9)},anchor=north west}.

Related Question