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.


% 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$};


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: