[Tex/LaTex] Graphing trigonometric functions, axes labeled with tick marks

pgfplotstikz-pgf

I am providing the code for graphing three trigonometric functions. (In the preamble, I had to put a % before the command \usetikzlibrary{calc,angles,quotes} because LaTeX could not compile it with the command. It gave me the error can't find file 'tikzlibraryangles.code.tex'. MikTeX2.9 is compiling the code.) How do I add the labels "$\scriptstyle{y = \sin(x)}," "$\scriptstyle{y = \cos(x)}," and "$\scriptstyle{y = \tan(x)}" directly under the y-axis to the corresponding graphs? Arrowheads should be at both ends of the axes. They are currently at one end. Is there a code for putting labels (in nodes) for the tick marks over other features of the graphs? How does the code instruct TikZ to marks the tick marks in half-unit increments? How do I get the code to instruct TikZ to mark the tick marks in increments of integral multiples of \pi/2? In the graphs of the tangent function, the asymptotes are solid lines. How do I get dotted lines? In the code for graphing the tangent function, there is "scaled x ticks={real:3.1415}, xtick scale label code/.code={}". What does "{real:3.1415}" and "code/.code={}" instruct TikZ to draw on the x-axis?

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
%\usetikzlibrary{calc,angles,quotes}
\usepackage{pgfplots}


\pgfkeys{/pgfplots/Axis Style/.style={
    width=13.5cm, height=5cm,
    axis x line=center, 
    axis y line=middle, 
    samples=100,
    ymin=-1.5, ymax=1.5,
    xmin=-7.0, xmax=7.0,
    domain=-2*pi:2*pi
}}


\begin{document}

\begin{tikzpicture}
\begin{axis}[
    Axis Style,
    xtick={
        -6.28318, -4.7123889, -3.14159, -1.5708,
        1.5708, 3.14159, 4.7123889, 6.28318
    },
    xticklabels={
        $-2\pi$, $-3\pi/2$, $-\pi$, $\pi/2$,
        $\pi/2$, $\pi$, $3\pi/2$, $2\pi$
    }
]
\addplot [mark=none, ultra thick, blue] {sin(deg(x))};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
    Axis Style,
    xtick={
        -6.28318, -4.7123889, -3.14159, -1.5708,
        1.5708, 3.14159, 4.7123889, 6.28318
    },
    xticklabels={
        $-2\pi$, $-3\pi/2$, $-\pi\hspace{0.30cm}$, $\pi/2$,
        $\pi/2$, $\pi\hspace{0.10cm}$, $3\pi/2$, $\hspace{0.25cm} 2\pi$
    }
]
\addplot [mark=none, ultra thick, red] {cos(deg(x))};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
    Axis Style,
    xtick={-6.28318, -4.7123889, ..., 6.28318},
    scaled x ticks={real:3.1415},
    xtick scale label code/.code={},
]
\addplot [mark=none, thin, brown] {tan(deg(x))};
\end{axis}
\end{tikzpicture}


\end{document}

Best Answer

You've asked quite a few questions! It's generally best to ask one, focused question on this site ;)

But, here's an attempt to get through your questions....

Labels, such as $y = \sin(x), would make the graphs more presentable. I guess directly under the y-axis.

You could use, for example,

\begin{axis}[
    Axis Style,
    xtick={
        -6.28318, -4.7123889, -3.14159, -1.5708,
        1.5708, 3.14159, 4.7123889, 6.28318
    },
    xticklabels={
        $-2\pi$, $-3\pi/2$, $-\pi$, $\pi/2$,
        $\pi/2$, $\pi$, $3\pi/2$, $2\pi$
    },
    ylabel={$y=\sin(x)$}, %<---- new bit
]

or else, for example,

...
\addplot [mark=none, ultra thick, blue] {sin(deg(x))};
\addlegendentry{$y=\sin(x)$} %<---- new bit
...

You might also want to adjust the legend position using legend pos=...

Arrowheads should be at both ends of the axes. They are currently at one end.

You can use,

\pgfkeys{/pgfplots/Axis Style/.style={
    width=.3\textwidth, %height=5cm,
    axis x line=center, 
    axis y line=middle, 
    samples=100,
    ymin=-1.5, ymax=1.5,
    xmin=-7.0, xmax=7.0,
    domain=-2*pi:2*pi,
    axis line style=<->,  %<----- new bit
}}

or otherwise use pgfplotsset (as demonstrated below).

The scale is suitable for the graphs of the sine and cosine functions but not for the tangent function. Maybe have the y-axis include -10 and 10.

Try using, for example,

\begin{axis}[
    Axis Style,
    xtick={-6.28318, -4.7123889, ..., 6.28318},
    scaled x ticks={real:3.1415},
    xtick scale label code/.code={},
    ymin=-10,ymax=10, %<---- new bit
]

Changing the scale for this graph may have the labels along the axes drawn over by the graph of the tangent function. Is there a code for putting labels (in nodes) over other features of a graph?

I believe you want the axis on top key for this.

Currently, the y-axes of the three graphs are aligned. How can I have the x-axes are aligned?

Remove the blank lines between your figures - note that you'll need to adjust the text width to get them to fit nicely - consider the geometry package for this.

What does mark=none instruct TikZ to do? What other options are there for mark?

mark=none means that you only get the curve, and not circles (or other marks) at the sample points along the way. There are a lot of other options - see Section 4.7 of the pgfplots for details.

Here's a complete bit of code to play with that implements the things I have mentioned.

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}
\usepackage{pgfplots}
\usepackage[margin=1cm]{geometry}
\pgfplotsset{Axis Style/.style={
    width=.3\textwidth, %height=5cm,
    axis x line=center,
    axis y line=middle,
    samples=100,
    ymin=-1.5, ymax=1.5,
    xmin=-7.0, xmax=7.0,
    domain=-2*pi:2*pi,
    axis line style=<->,
}}


\begin{document}

\begin{tikzpicture}
    \begin{axis}[
            Axis Style,
            xtick={
                -6.28318, -4.7123889, -3.14159, -1.5708,
                1.5708, 3.14159, 4.7123889, 6.28318
            },
            xticklabels={
                $-2\pi$, $-3\pi/2$, $-\pi$, $\pi/2$,
                $\pi/2$, $\pi$, $3\pi/2$, $2\pi$
            },
            ylabel={$y=\sin(x)$},
        ]
        \addplot [mark=none, ultra thick, blue] {sin(deg(x))};
        \addlegendentry{$y=\sin(x)$}
    \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
    \begin{axis}[
            Axis Style,
            xtick={
                -6.28318, -4.7123889, -3.14159, -1.5708,
                1.5708, 3.14159, 4.7123889, 6.28318
            },
            xticklabels={
                $-2\pi$, $-3\pi/2$, $-\pi\hspace{0.30cm}$, $\pi/2$,
                $\pi/2$, $\pi\hspace{0.10cm}$, $3\pi/2$, $\hspace{0.25cm} 2\pi$
            }
        ]
        \addplot [mark=none, ultra thick, red] {cos(deg(x))};
    \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
    \begin{axis}[
            Axis Style,
            xtick={-6.28318, -4.7123889, ..., 6.28318},
            scaled x ticks={real:3.1415},
            xtick scale label code/.code={},
            ymin=-10,ymax=10,
        ]
        \addplot [mark=none, ultra thick, brown] {tan(deg(x))};
    \end{axis}
\end{tikzpicture}


\end{document}