4

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}
  • 2
    In all the math texts I have, axis arrowheads point in the positive direction only, not both directions, and functions do not have arrowheads. I've always believed that was intentional, that the purpose of an arrowhead was to indicate which way the axis was oriented. (Of course, that always seems to be up and to-the-right by convention.) – dedded Sep 21 '17 at 19:14
  • I was really hoping that this was a convention I could overwrite and make the way I teach the content to HS Students. Sigh. – C. L. Butler Sep 21 '17 at 19:15
  • I assume pgfplots gives that control. But I'm not sure what the meaning of arrowheads on axes would be if you put them on both ends. What are you trying to express? – dedded Sep 21 '17 at 19:19
5

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.

  • Sina - this looks amazing and exactly what I was hoping. I think I just need to adjust the domain of the function and the size of the window to show what I want. Thanks! – C. L. Butler Sep 21 '17 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.