I modified someone's code and get the trigonometric graph I want. But I wonder if there is an easier/elegant code than this.
Specifically, I'd like to have an automatic node setting instead of listing them all. Also, is there an easier way to graph a trig function? I found the addplot feature but it doesn't seem to work in the current code/environment (which is what I prefer).
Thank you.
\documentclass[oneside]{book}
\usepackage{amsmath, amsthm}
\usepackage{forloop, tikz, realboxes}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=1cm,y=1.5cm]
\def\xmin{-2*pi}
\def\xmax{2*pi}
\def\ymin{-2}
\def\ymax{2}
% grid
\draw[style=help lines, ystep=1, xstep=pi/4] (\xmin,\ymin) grid (\xmax,\ymax);
% axes
\draw[thick, ->] (\xmin-.25,0) -- (\xmax+.25,0) node[right] {$x$};
\draw[thick, ->] (0,\ymin-.25) -- (0,\ymax+.25) node[above] {$y$};
% xticks and yticks
\foreach \x in {-6.28319,-5.4978, ..., 6.28319}{
\draw (\x,2pt) -- (\x,-2pt);
\node[fill=white] at (-2*pi, -.2) [below] {{$- 2\pi$}};
\node[fill=white] at (-7*pi/4, -.1) [below] {\tiny{$\dfrac{-7\pi}{4}$}};
\node[fill=white] at (-3*pi/2, -.1) [below] {\tiny{$\dfrac{-3\pi}{2}$}};
\node[fill=white] at (-5*pi/4, -.1) [below] {\tiny{$\dfrac{-5\pi}{4}$}};
\node[fill=white] at (-pi, -.2) [below] {{$-\pi$}};
\node[fill=white] at (-3*pi/4, -.1) [below] {\tiny{$\dfrac{-3\pi}{4}$}};
\node[fill=white] at (-pi/2, -.1) [below] {\tiny{$\dfrac{-\pi}{2}$}};
\node[fill=white] at (-pi/4, -.1) [below] {\tiny{$\dfrac{-\pi}{4}$}};
%
\node[fill=white] at (2*pi, -.2) [below] {{$2\pi$}};
\node[fill=white] at (7*pi/4, -.1) [below] {\tiny{$\dfrac{7\pi}{4}$}};
\node[fill=white] at (3*pi/2, -.1) [below] {\tiny{$\dfrac{3\pi}{2}$}};
\node[fill=white] at (5*pi/4, -.1) [below] {\tiny{$\dfrac{5\pi}{4}$}};
\node[fill=white] at (pi, -.2) [below] {{$\pi$}};
\node[fill=white] at (3*pi/4, -.1) [below] {\tiny{$\dfrac{3\pi}{4}$}};
\node[fill=white] at (pi/2, -.1) [below] {\tiny{$\dfrac{\pi}{2}$}};
\node[fill=white] at (pi/4, -.1) [below] {\tiny{$\dfrac{\pi}{4}$}};
}
\foreach \y in { -2, -1, 1, 2}
\draw (2pt, \y) -- (-2pt, \y);
\foreach \y in {-2, -1, 1, 2}
\node[fill=white] at (-.1,\y) [left] {\y};
\draw[ultra thick, red]
(-2*pi-pi/4,1) sin (-3*pi/2-pi/4,2) cos (-pi-pi/4,1) sin (-pi/2-pi/4,0) cos (0-pi/4,1)
sin (pi/2-pi/4,2) cos (pi-pi/4,1) sin (3*pi/2-pi/4,0) cos (2*pi-pi/4,1) sin (5*pi/2-pi/4,2);
\end{tikzpicture}
\end{document}
That is, instead of
\draw[ultra thick, red]
(-2*pi,0) sin (-3*pi/2,1) cos (-pi,0) sin (-pi/2,-1) cos (0,0)
sin (pi/2,1) cos (pi,0) sin (3*pi/2,-1) cos (2*pi,0);
I'd like to use something like this:
\draw[scale=1,domain=-1.5:3.5,smooth,variable=\x,blue, thick] plot ({\x},{sin \x});


\documentclassand end with\end{document}... ;). – cfr Jul 05 '15 at 03:18\addplotwill do things like generating the axes and ticks automatically. You say you want that but you don't...? – cfr Jul 05 '15 at 03:20axisenvironment as shown in that link. (And load the package, of course.) – cfr Jul 05 '15 at 03:38