tikz and gnuplot on OS X

TikZ is a great LaTeX package for graphics. Its plot directive gives an easy way to plot functions, but this relies on gnuplot being available. On OS X this is a little tricky. Assuming you use MacPorts, try this:

sudo port install gnuplot
sudo ln -s which gnuplot /usr/local/bin/gnuplot

Now here’s a minimal example, with a function, axes, and tick marks.

\documentclass{amsart}

\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% the plot
\draw[smooth,domain=0:6.5] plot function{sin(2*x)*exp(-x/4)};

% axes
\draw[->] (-0.2,0) -- (7,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,1.2) node[above] {$f(x)$};

% tick marks
\foreach \x/\xtext in {1/1, 2/2, 3/3, 4/4, 5/5, 6/6}
\draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};

\foreach \y/\ytext in {-1/-1, 1/1}
\draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt) node[left] {$\ytext$};
\end{tikzpicture}

\end{document}