# Problem with contour plots

Im trying to run the following code

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width = 7cm, compat = 1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain = -2:2, domain y = 0:2*pi]
\addplot3[contour gnuplot = {output point meta = rawz, number=10, labels=false}, samples = 41, z filter/.code=\def\pgfmathresult{-1.6}] {exp(-x^2) * sin(deg(y))};
\addplot3[surf, samples = 25] {exp(-x^2) * sin(deg(y))};
\end{axis}
\end{tikzpicture}
\end{document}


and I'm getting the error

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


through a quick search I found out that contour maps require pgfplots and gnuplot to talk to each other. In theory the way to make them interact is adding

!TEX option = --enable-write18


or

%!TEX option = --enable-escape


at the top of the file. Unfortunately this has not worked for me. Any suggestions?

• When I run your code with pdflatex -shell-escape, it works beautifully. Perhaps this means you need to say !TEX option = -shell-escape. – user121799 Oct 22 '18 at 21:23
• Just tried adding % !TEX option = -shell-escape before/after \begin{document}, still no luck – noibe Oct 22 '18 at 22:28
• OK, then could you please tell us how you compile it? (And what happens if you add a -, i.e. use % !TEX option = --shell-escape?) – user121799 Oct 22 '18 at 22:44
• If you hit enter does it continue to compile with the following warnings Package pgfplots Error: sorry, plot file{untitled-2_contourtmp0.table} could not be opened. See the pgfplots package documentation for explanation. Type H <return> for immediate help. ... l.7 ...athresult{-1.6}] {exp(-x^2) * sin(deg(y))}; Package pgfplots Warning: the current plot has no coordinates (or all have been filtered away) on input line 7. – user170109 Oct 23 '18 at 0:41
• Ok have now added a diagnostic MWE to my answer. – user170109 Oct 24 '18 at 17:07

After testing dozens of similar issues, and trying to develop a "simple" diagnostic MWE.

The message is very clear [sic] Utitlled_contourtmp0.table is not generated thus is not available, this seems to be an all too common problem with contour gnuplot and the two solutions are relatively simple.

1) -shell-execute needs to be active

2) \yourpathto\gnuplot\bin needs to be on your editors path

The following test script should help Windows users feel free to duplicate for mac/nix

\documentclass[border=10pt]{standalone}
\RequirePackage{ifplatform}
\usepackage{ifpdf}
%% First sanity test if pdfLaTeX is active
\ifpdf
\errmessage{OK ! pdfLaTeX IS active PRESS ENTER TO CONTINUE}
\else
\errmessage{plain latex and dvipdf ? PLEASE SWITCH to pdfLaTeX}
\fi
%% Second sanity test if shell escape is available
\ifshellescape
\errmessage{OK   Shell-Escape IS active  PRESS ENTER TO CONTINUE}
\else
\fi
\begin{document}
%% if shell escape is working we can get console feedback
\def\tmpfile{w18-active-\the\year\the\month\the\day\the\time.cmd}
\immediate\write18{echo echo Shell-Escape is active > "\tmpfile"}
\ifpdf
\immediate\write18{echo echo You are using pdflatex >> "\tmpfile"}
\else
\immediate\write18{echo echo plain latex and dvipdf ? switch to pdflatex >> "\tmpfile"}
\fi
% Check where gnuplot is Fist check if we can get version info
\immediate\write18{echo gnuplot -e  "show version long" >> "\tmpfile"}
% these lines are under review as it should traverse editor roots, but for present we check relative and system path
\immediate\write18{echo where /r . gnuplot.exe >> "\tmpfile"}
\immediate\write18{echo where gnuplot.exe >> "\tmpfile"}

\immediate\write18{echo set path >> "\tmpfile"}
% Store latest results WILL be overwritten on each run
\immediate\write18{"\tmpfile" >results.txt}
% Add a pause in case user wants to manually edit / run cmd file
\immediate\write18{echo pause>> "\tmpfile"}
\immediate\write18{"\tmpfile"}
\immediate\write18{del "\tmpfile"}
ALL DONE SEE CONSOLE OUTPUT OR Results.txt
\end{document}