[Tex/LaTex] TikZ + gnuplot on a Mac

gnuplotmactikz-pgf

I'm using LaTeX a lot in my work and I switched to Mac recently. I installed TeX Live and everything works fine, except for plotting a figure with gnuplot.

I installed gnuplot 4.4.3 first simply in the Terminal as I read in the internet, but didn't work, then after surfing I installed Fink and Macports and gnuplot again through Macports. I know it's a mess, but the error message hasn't changed, it has remained the same, which is the following:

gnuplot> set table "proba.f0.table"; set format "%.5f"
             ^
         "proba.f0.gnuplot", line 1: valid set options:  [] = choose one, {} means optional

    'angles', 'arrow', 'autoscale', 'bars', 'border', 'boxwidth',
    'clabel', 'clip', 'cntrparam', 'colorbox', 'contour', 'decimalsign',
    'dgrid3d', 'dummy', 'encoding', 'fit', 'format', 'grid',
    'hidden3d', 'historysize', 'isosamples', 'key', 'label', 'locale',
    'logscale', '[blrt]margin', 'mapping', 'mouse', 'multiplot',
    'offsets', 'origin', 'output', 'palette', 'parametric', 'pm3d',
    'pointsize', 'polar', 'print', '[rtuv]range', 'samples', 'size',
    'style', 'surface', 'terminal', tics', 'ticscale', 'ticslevel',
    'timestamp', 'timefmt', 'title', 'view', '[xyz]{2}data',
    '[xyz]{2}label', '[xyz]{2}range', '{no}{m}[xyz]{2}tics',
    '[xyz]{2}[md]tics', '{[xyz]{2}}zeroaxis', 'zero'



Package pgf Warning: Plot data file `proba.f0.table' not found. on input line 4
6.

The Latex code is the following:

\documentclass[trans]{beamer}

\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsmath,amsthm}
\usepackage{pgffor}
\usepackage{tikz}
\usepackage{hyperref}

\newenvironment{stepenumerate}{\begin{enumerate}[<+->]}{\end{enumerate}}
\newenvironment{stepitemize}{\begin{itemize}[<+->]}{\end{itemize} }
\newenvironment{stepenumeratewithalert}{\begin{enumerate}[<+-| alert@+>]}{\end{enumerate}}
\newenvironment{stepitemizewithalert}{\begin{itemize}[<+-| alert@+>]}{\end{itemize} }
\usetheme{CambridgeUS}
%\useoutertheme[footline=authortitle]{miniframes}
%\setbeamercovered{still covered={\opaqueness<1->{25}}} 
\setbeamercovered{invisible}
\usefonttheme{structurebold}

\begin{document}


\begin{frame}
  \frametitle{P.d.f. with different degrees of freedom}

  \begin{center}
  \begin{tikzpicture}[y=5cm]
    \draw[domain=0:4,thick,color=orange] plot[id=f0,samples=100] 
       function{0.5*(gamma(3)/(gamma(1)*gamma(2)))*1/((1+0.5*x)**3)} node at (1,0.8) {$\scriptstyle n=2\textsf{,}\; m=4$};

    \draw (0,0) node[below left] {$0$};
    \draw (3.5,1) node[above] {$\scriptstyle f\left(x;n,m\right)=\left(\frac{n}{m}\right)^{\frac{n}{2}}\frac{\Gamma\left(\frac{n+m}{2}\right)}{\Gamma\left(\frac{n}{2}\right)\Gamma\left(\frac{m}{2}\right)}\frac{x^{\frac{n}{2}-1}}{\left(1+\frac{n}{m}x\right)^{\frac{n+m}{2}}}$};

    \draw[->,semithick] (-0.2,0) -- (4.2,0) node[right] {$x$};
    \draw[->,semithick] (0,-0.05) -- (0,1.2) node[left] {$f\left(x\right)$};

    \foreach \x in {1,2,...,4}
      \draw (\x,2pt) -- (\x,-2pt) node[below] {\x};
    \foreach \y in {0.2,0.4,0.6,0.8,1}
      \draw (2pt,\y) -- (-2pt,\y) node[left] {\y};
  \end{tikzpicture}
  \end{center}

  \transwipe
\end{frame}

\end{document}

What can the problem be? I'm unable to solve it, but I'd like to use gnuplot on my Mac.


Edit 1 (moved here from an answer by a moderator)

Thanks a lot for the quick replies. I'm sorry, but I didn't clarify a couple of issues.

  1. I'm using TexShop and it works fine.
  2. --shell-escape is configured, and also -enable-write18
  3. gnuplot works, although I think I installed it twice… When in Terminal I write gnuplot, it starts gnuplot 4.4 with patchlevel 3, but when I write /usr/local/bin/gnuplot, it starts gnuplot 4.0 with patchlevel 0. The first set aquaterm (which is installed) and doesn't plot, and the second X11 (also installed) which works well. Can this be the problem? Which one should I keep and how to uninstall the other?
  4. Placing & -shell-escapeat the beginning of the document results in an error message: Misplaced alignment tab character &
  5. Since gnuplot doesn't work, I use now pgfplot which is also great, but gnuplot is more flexible and I can represent more functions with it.
  6. Some recommended on other sites to change the pgfmoduleplot.code.tex file and change the line

    \xdef\pgf@gnuplot@head#1{set terminal table; set output “#1.table”; set format “%.5f”} 
    

    to

    \xdef\pgf@gnuplot@head#1{set table; set output “#1.table”; set format “%.5f”}
    

    However, I have no such a line, but have

     \xdef\pgf@gnuplot@head{set table \noexpand\pgf@plottablefile@quoted; set format "%.5f"}
    

Edit 2 (moved here from an answer by a moderator)

I think I found out where the problem lies. As I wrote before, I have two gnuplots installed. When in Terminal I write gnuplot, it starts gnuplot 4.4 with patchlevel 3, but when I write /usr/local/bin/gnuplot, it starts gnuplot 4.0 with patchlevel 0.

I tried to create the gnuplot table in the terminal by gnuplot proba.f0.gnuplot and it worked well and then TexShop could make the job. However, when i tried with the other version and wrote /usr/local/bin/gnuplot proba.f0.gnuplot it gave me the familiar error message.

So the problem must be with version 4.0. How can I uninstall it from /usr/local/bin and put the other one there?

Edit 3

@Altermundus: Thanks a lot, I was able to uninstall gnuplot from /usr/local/bin. Now the only thing I have to do is to make Texshop find gnuplot in /opt/local/bin, because that version works manually. How could I do that?

Best Answer

  1. First you need to test if gnuplot works. I compiled the source but you can work with a fink or macport version;
  2. Now you can test gnuplot in the terminal $ gnuplot;
  3. Then gnuplot must be find in the path. A simple solution is to create a link for example in /usr/local/bin/ through the real file gnuplot but if you know how do you can modifify your path directly (to test the path in the terminal :$ echo $PATH)
  4. And finally, you need to authorize TeXto launch 'gnuplotwith--shell-escape`in your script for the compilation.

I don't like very much the use of Fink or Macport and I prefer to compile the sources. By default the binary will be inside /usr/local/bin ( I think ..) but it's easy to change. The next method is only to get a version to use with tikz and to get a table. It's more complicate to get a version with all terminals (png, etc.) A good thing is to install Aquaterm !

  1. Download the sources from : gnuplot sources then put the folder gnuplot-4.4.3 on your desktop
  2. $ cd /Users/.../Desktop/gnuplot-4.4.3
  3. $ ./configure --with-readline=builtin to avoid a problem with a bad readline on Leopard.
  4. $ make
  5. $ sudo make install
  6. test of gnuplot $ gnuplot
  7. make a try with TexShop, this is the easiest way to work with TeX.