Drawing graphs using tikz/pgf & gnuplot

Combining the tikz package with gnuplot allows you to plot graphs without ever leaving your favorite editor.  Adding the tikz package is straightforward as with other LaTeX packages but everytime I run into trouble installing gnuplot.  As far as I can tell the following steps are sufficient and necessary to get tikz and gnuplot to play nicely together.

  • Download gnuplot and unzip in some folder, e.g., C:\gnuplot.  Subsequently add C:\gnuplot\bin\ as a path to your environment variables.
  • If you have downloaded the windows version of gnuplot then change the name of the executable from ‘wgnuplot.exe’ to ‘gnuplot.exe’.
  • gnuplot may be prevented from writing in the current directory when it is called by tikz.  Use the –enable-write18 switch when compiling your document, e.g., pdflatex –enable-write18 foo.tex.  If you use WinEdt, the switch can be added under Options-Executions Modes.   Note that the first ‘-‘ in –enable-write18 should be two ‘-‘.
  • gnuplot doesn’t seem to like spaces in filenames.