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 have two surface plots, which I would like to have to same color for the same height. So, as the first plot is dark blue for f(x,y)=0, the right plot should also be dark blue for f(x,y)=0. However, the color dark blue is assigned to the lowest point of the plot. Thus, the color for f(x,y) in the right plot is a bright orange.

Sample source:

\documentclass{report}
\usepackage{pgfplots}

\begin{document}

% first plot
\begin{tikzpicture}
\begin{axis}[]
\addplot3[surf,colormap name=hot,domain=-2:2] {exp(-x^2-y^2)};
\end{axis}
\end{tikzpicture}

% second plot
\begin{tikzpicture}
\begin{axis}[]
\addplot3[surf,colormap name=hot,domain=-2:2] {exp(-x^2-y^2)-exp(-(x-1)^2-(y-1)^2)};
\end{axis}
\end{tikzpicture}

\end{document}

How can I force the plots to have the same color for the same height?

share|improve this question
    
Do the plot shapes look like you want them to? Are you trying to plot z=e^(-(x^2)-(y^2)) or z=e^((-x)^2+(-y)^2)? –  Jake Dec 22 '11 at 22:15
    
Actually the pictures above are not the plots of my example, the correct pictures can be found in the answer below. I dont know why Werner has modified my plotting functions. Anyway, I actually want to plot something totally different, the Gaussian function is just here to show what I am talking about. Also note that z=e^((-x)^2+(-y)^2) = z=e^(x^2+y^2), so I do not understand your question. –  Peter Dec 23 '11 at 8:49
    
Yeah, (-x)^2 = x^2, but that's not what I wrote. I said -(x^2). –  Jake Dec 23 '11 at 12:50
    
@Werner: Which version of PGF and PGFplots do you use? I get a different output from compiling Peter's code than the image you embedded, using tikz.sty 2010/10/13 v2.10 and pgfplots.sty 2011/07/29 v1.5 –  Jake Dec 23 '11 at 12:55
    
@Jake: Perhaps you can update the image with the appropriate output, since I added it from a system still running TeX Live 2009. I had thought an image would clearly show the problem, but if the output differs greatly, change or remove it. –  Werner Dec 23 '11 at 15:50
show 1 more comment

1 Answer

up vote 11 down vote accepted

By default, PGFplots will stretch the colormap to span the whole range of meta values (which, by default, are the y values) of all the plots in the axis. In your case, you would need to set the range explicitly. You can do this using point meta min=... and point meta max=....

\documentclass{report}
\usepackage{pgfplots}

\begin{document}

% first plot
\begin{tikzpicture}
\begin{axis}[point meta min=-1, point meta max=1]
\addplot3[surf,colormap name=hot,domain=-2:2] {exp(-x^2-y^2)};
\end{axis}
\end{tikzpicture}

% second plot
\begin{tikzpicture}
\begin{axis}[point meta min=-1, point meta max=1]
\addplot3[surf,colormap name=hot,domain=-2:2] {exp(-x^2-y^2)-exp(-(x-1)^2-(y-1)^2)};
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
That works perfectly! –  Peter Dec 23 '11 at 8:47
add comment

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.