[Tex/LaTex] Arrowheads on Axes and Function

arrowspgfplotstikz-pgf

I'm trying to put arrowheads on both my axes and my function to no avail.

enter image description here

I would like to have the arrows on the left and the bottom of my axes as well as at the end of my function (both sides).

This is my code:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
grid=both,
axis lines=center,
domain=-2*pi:2*pi,
samples=200,
no marks,
xticklabels={-2$\pi$,-1.5$\pi$,...$\pi$,2$\pi$},
xtick={-6.2832,-4.7124,...,6.2832},
x post scale=1.5
]
\addplot {sin(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}

Best Answer

In order to add the arrows to the both sides of your axes, you may add axis line style={latex-latex} option to your plot style.

Here is my solution for your problem:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
grid=both,
axis lines=center,
domain=-2*pi:2*pi,
samples=200,
no marks,
axis line style={latex-latex},
xticklabels={-2$\pi$,-1.5$\pi$,...$\pi$,2$\pi$},
xtick={-6.2832,-4.7124,...,6.2832},
x post scale=1.5
]
\addplot+[<->,mark=none,line width=1pt] {sin(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}

which produces the following plot:

enter image description here

You may widen the line of the plot so that the arrows in the two extremities can be seen more evidently.