# Contour plot of arbitrary R^3 function without gnuplot

Is there a way to make pretty contour plots of arbitrary functions in R^3, like the one below for example, without the use of the gnuplot contour-stuff?

The reason I'm asking is I prefer a simple setup of the TeX environment, and since gnuplot isn't included in the Mactex bundle, and requires some adjustments to command line calls etc. I prefer to just solve things with what's available, if feasibly possible.

One obvious way would be to manually calculate the contours, but I saw this solution below and really liked that it took a single function for the surface and produced the contours on its own. • Asymptote, which is included in the MacTeX bundle, has a module for this. – Charles Staats Feb 7 '14 at 19:46

pgfplots currently supports contour plots if they are either precomputed by means of some external program (contour prepared) or it can invoke an external tool to compute them as in contour gnuplot.

An implementation to compute the contours in TeX was attempted, but the contributor had to pursue his studies and could not finish it.

Means: No, this is currently impossible with pgfplots.

That means: pgfplots has to resort to gnuplot or "some other suitable external tool".

If someone would like to implement a contouring algorithm in, say, Lua, one could also integrate that.

• Ok, I will make my own contour plots manually in pgfplots! – Jay Feb 9 '14 at 1:13

If you don't mind the Python based matplotlib example referred to above (note, there are more pleasant looking graphics here) then sagetex is an option since it allows you to run Python code.

\documentclass{article}
\usepackage{sagetex}
\usepackage{graphicx}
\pagestyle{empty}
\begin{document}
\begin{sagesilent}
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
cset = ax.contourf(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)

ax.set_xlabel('X')
ax.set_xlim(-40, 40)
ax.set_ylabel('Y')
ax.set_ylim(-40, 40)
ax.set_zlabel('Z')
ax.set_zlim(-100, 100)

plt.savefig('Contour.png')
\end{sagesilent}
Sagetex let's you borrow the power of Python in creating pictures. This
example comes from:
\begin{verbatim}
http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#surface-plots
\end{verbatim}
and it's running in \LaTeX \,with the power of the sagetex package.
\begin{center}
\includegraphics[width=5in,height=4in]{Contour.png}
\end{center}
\end{document}


Which gives this output when running on the Sagemath Cloud site: 