[Tex/LaTex] Help with installing gnuplot in MacTex and using it with LaTeX

gnuplottikz-pgf

I have to draw a lot of PDF and CDF graphs in my document/presentation and in order to do that I installed gnuplot. In order to install gnuplot I took the following steps:

1- Download the sources from : gnuplot sources then put the folder gnuplot-4.4.3 on my desktop
2- $ cd /Users/…/Desktop/gnuplot-4.4.3
3- $ ./configure –with-readline=builtin
4- $ make
5- $ sudo make install
6- test of gnuplot $ gnuplot
gnuplot works from Terminal. However, I get a lot of error running the followingMWE

\documentclass{minimal}
\usepackage{amsmath}
\usepackage{pgfplots}

\def\cdf(#1)(#2)(#3){0.5*(1+(erf((#1-#2)/(#3*sqrt(2)))))}%
% to be used: \cdf(x)(mean)(variance)

\DeclareMathOperator{\CDF}{cdf}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[%
    xlabel=$x$,
    ylabel=$\CDF(x)$,
    grid=major]
    \addplot[smooth,red] gnuplot{\cdf(x)(0)(1)};
    \addplot[smooth,blue]gnuplot{\cdf(x)(0.5)(1)};
    \addplot[smooth,green]gnuplot{\cdf(x)(1)(1)};
    \addplot[smooth,orange]gnuplot{\cdf(x)(2)(1)};
    \end{axis}
    \end{tikzpicture}
\end{document}

The error that I get is

pgfplots: Sorry, the gnuplot-result file 'texstudio_DH7974.pgf-gnuplot <file>.gnuplot' manually on the respective gnuplot file.. \addlegendentryexpanded{$k = \k$}}

or code given in plotting chi-square. I guess I am missing one (or maybe cuple) of steps installing gnuplot. I really appreciate if you help.

Best Answer

Since you can run gnuplot from the Terminal, you have installed it correctly. But you also need to configure pdflatex to allow it to run external programs. Since you are using TeXStudio you need to go into its preferences and change the entry for pdflatex. See

for details on this. So the correct line to allow you to run gnuplot from within a LaTeX document is:

 pdfLaTeX    "/usr/texbin/pdflatex" -synctex=1 -interaction=nonstopmode -shell-escape %.tex    
Related Question