Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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).

Surface plot below, 2D plot above

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

    \addplot3[
    surf,
    shader=faceted interp,
    samples=10,
    z filter/.code={\def\pgfmathresult{1.4}}
    ] {sin(deg(x))*sin(deg(y))};
  \end{axis}
\end{tikzpicture}
\end{document}
share|improve this question
1  
Related : pgfplots: color a surf using arbitrary colors. I found it after the answer was posted here, while searching for something totally different :) . –  Georges 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
1  
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
add comment

1 Answer

up vote 7 down vote accepted

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]
    \addplot3[
    surf,
    shader=faceted interp,
    samples=10,
    ] {sin(deg(x))*sin(deg(y))};

    \addplot3[
    surf,
    shader=faceted interp,
    samples=10,point meta rel=per plot,
    point meta={sin(deg(x))*sin(deg(y))}
    ] {1.4};
  \end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
My viewer is also evince, under ubuntu. Oh well… Could you please post the code for your answer? –  Georges Dupéron Feb 9 '13 at 22:13
    
@GeorgesDupéron: Sorry, forgot about that. Question is edited. –  Jake Feb 9 '13 at 22:14
    
@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
1  
@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
1  
@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 :) . –  Georges Dupéron Feb 11 '13 at 12:55
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.