I'm looking to generate sine waves in tikz which go in increments of pi/6 (or some other radian increments). I would like the tick mark labels to be in reduced fraction form with no coefficient in front of the pi's when it's unnecessary.
Here is what I created myself:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns, shapes, arrows}
\usetikzlibrary{calc}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\[
\begin{tikzpicture}[scale=2]
\draw[->,thick] (-6.5,0) -- (6.5,0) node[right] {$x$};
\draw[->,thick] (0,-1.25) -- (0, 1.25) node[above] {$y$};
\foreach \s in {-12,-11,...,12}
\draw[thin, gray] ({0.524*\s}, -1.25) -- ({0.524*\s}, 1.25);
\foreach \t in {-1,-1/2,1/2,1}
\draw[thin, gray] (-6.5,\t) -- (6.5,\t);
\foreach \u in {-12,-11,...,12}
\draw ({0.524*\u}, -0.1) -- ({0.524*\u}, 0.1);
\foreach \v in {-1,-1/2,1/2,1}
\draw (0.1,\v) -- (-0.1,\v) node[fill=white, left] {$\v$};
\foreach \w in {-11,-7,-5,5,7,11}
\node[fill=white, below] at ({0.524*\w}, -0.1){$\frac{\w\pi}{6}$};
\foreach \x in {-5,-4,-2,2,4,5}
\node[fill=white, below] at ({1.047*\x}, -0.1) {$\frac{\x\pi}{3}$};
\foreach \y in {-3,3}
\node[fill=white, below] at ({1.571*\y}, -0.1) {$\frac{\y\pi}{2}$};
\node[fill=white, below] at (-3.142,-0.1) {$-\pi$};
\node[fill=white, below] at (3.142,-0.1) {$\pi$};
\foreach \z in {-2,2}
\node[fill=white, below] at ({3.142*\z}, -0.1) {$\z\pi$};
\node[fill=white, below] at (-1.571,-0.1) {$-\frac{\pi}{2}$};
\node[fill=white, below] at (1.571,-0.1) {$\frac{\pi}{2}$};
\node[fill=white, below] at (-1.047,-0.1) {$-\frac{\pi}{3}$};
\node[fill=white, below] at (1.047,-0.1){$\frac{\pi}{3}$};
\node[fill=white, below] at (-0.524,-0.1) {$-\frac{\pi}{6}$};
\node[fill=white, below] at (0.524,-0.1) {$\frac{\pi}{6}$};
\draw[<->,thick,domain=-6.5:6.5,samples=300,variable=\x] plot ({\x},{sin(57.296*\x)});
\end{tikzpicture}
\]
\end{document}
As you can see, this was a lot of work, which is fine, but I'm planning to generate a lot of graphs like this. Due to the ubiquity of sine graphs, it seems like someone would have come up with something easier.
One further comment: I'm aware that pspicture can be used to generate fantastic sine graphs (e.g. Graphing trigonometric functions, axes labeled with tick marks). But I have two problems (1) I plead ignorance on the functionality of the pspicture package, and (2) it seems to require graph specific code in the preamble which could turn into quite a mess if a lot of graphs are generated.
Best Answer
Like this (pure TikZ solution):
However, this can be also done by
pgfplots
.