# 2D colors above 3D surface plot

I would like to draw a 2D, colored plot of a function above its surface plot.

I tried copying the surface plot and setting z filter/.code={\def\pgfmathresult{1.4}}, but then everything is the same color on the 2D plot.

Also, I'd be glad if I could avoid the antialiasing artifacts on the 2D plot (each quad is made of two triangles, and there is a small white line between them).

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=both]
surf,
samples=10,
] {sin(deg(x))*sin(deg(y))};

surf,
samples=10,
z filter/.code={\def\pgfmathresult{1.4}}
] {sin(deg(x))*sin(deg(y))};
\end{axis}
\end{tikzpicture}
\end{document}

• Related : pgfplots: color a surf using arbitrary colors. I found it after the answer was posted here, while searching for something totally different :) . – Suzanne Dupéron Feb 9 '13 at 22:21
• The triangulation (quad->triangles) is actually a bug in some older version of pgfplots, not some kind of viewing artifact. It was (only) present for shader=faceted interp. It has been fixed in the meantime; an upgrade to the current stable version will eliminate it. – Christian Feuersänger Feb 11 '13 at 7:01
• Just a side note: highly oscillating functions like yours involve a relatively high resolution in order to look smooth. A potentially interesting alternative is to use \usepgfplotslibrary{patchplots} and add the two options patch type=bicubic, patch type sampling, to your surface plot. This will cause a much smoother surface. Works only with plot-by-expression, though. – Christian Feuersänger Feb 11 '13 at 7:10

The color of the plot depends on the meta value, which by default, is the z value in 3D plots. You can set it to something else, however: In this case, you'd say point meta={sin(deg(x))*sin(deg(y))} (so you'd use the original function for the meta value), and simply plot {1.4} instead of the function:

About the artifacts: That's probably a viewer issue. I don't see them using Adobe Reader or Evince on Ubuntu Linux.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=both]
surf,
samples=10,
] {sin(deg(x))*sin(deg(y))};

surf,

• @Jake, I'm getting errors: pgfkeys: Choice '1.7' unknown in key '/pgfplots/compat/anchors'. I am going to ignore this key. \pgfplotsset{compat=1.7} and others. – Sigur Feb 9 '13 at 22:50
• @Sigur: Then you're probably using a version of PGFPlots older than 1.7. Just use compat=newest. – Jake Feb 10 '13 at 9:31
• @Sigur otherwise just use one of the following for the shader= key : flat, flat corner, interp, facetted, facetted interp (There are a few more I think, check the documentation), or just remove that key. facetted gives the "lines" you see between the pathces, and interp makes the patches colored by a gradient, instead of having a single color. But yes, you should upgrade your pgfplots package :) . – Suzanne Dupéron Feb 11 '13 at 12:55