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....
You could use, for example,
or else, for example,
You might also want to adjust the legend position using
legend pos=...
You can use,
or otherwise use
pgfplotsset
(as demonstrated below).Try using, for example,
I believe you want the
axis on top
key for this.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.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 thepgfplots
for details.Here's a complete bit of code to play with that implements the things I have mentioned.