[Tex/LaTex] Contour plot error with pgfplot and tikz

pgfplotstikz-pgf

I'm trying to plot contour lines of a two variable function. I found this example here:

\begin{tikzpicture}
\begin{axis}[view={0}{90}]
\addplot3[contour gnuplot={
    labels over line,number=9}]
    {x*y};
\end{axis}
\end{tikzpicture}

But I get the following error:

! Package pgfplots Error: sorry, plot file{plots_contourtmp0.table}
could not be opened.

What is going on?

Best Answer

This example invokes the external program gnuplot to compute coordinates.

By default latex doesn't allow to launch such external executables because of potential dangers connected with compiling arbitrary sources that might invoke malicious commands without you noticing.

So you need to explicitly enable external program calls with the -shell-escape command-line option:

pdflatex -shell-escape filename.tex

This is documented pretty well in pgfplots manual (section 4.3.5, rev 1.12.1).