# Color three dimensional plot and contour plot the same

Consider:

f[x_, y_] = 6 - 3 x - 2 y;
GraphicsRow[{
Plot3D[f[x, y], {x, -4, 4}, {y, -4, 4},
MeshFunctions -> {#3 &}],
ContourPlot[f[x, y], {x, -4, 4}, {y, -4, 4},
Contours -> 15,
PlotLegends -> Automatic]
}]


How can I make the Plot3D colors exactly the same as the contour plot colors, shading according to height with the same color strategy as in the contour plot.

• You need to learn the difference between = and :=. Your function should be defined as f[x_, y_] := 6 - 3 x - 2 y to protect it from being "destroyed" by assignments to x or y. Recommend you read through this community wiki – m_goldberg Oct 5 '15 at 16:39

f[x_, y_] = 6 - 3 x - 2 y;
GraphicsRow[{
Plot3D[f[x, y], {x, -4, 4}, {y, -4, 4},
MeshFunctions -> {#3 &}, ColorFunction -> "DarkRainbow"],
ContourPlot[f[x, y], {x, -4, 4}, {y, -4, 4}, Contours -> 15,
PlotLegends -> Automatic, ColorFunction -> "DarkRainbow"]}]


• I often also explicitly specify the PlotRange->{All,All,{zMin,zMax}} in case I to apply this to different functions for comparison. – N.J.Evans Oct 5 '15 at 15:56
• @N.J.Evans Can you show how you do this with an answer? Thank you. – David Oct 5 '15 at 17:29
• @Algohi Nice answer. But how can I determine the default color function used by ContourPlot. I'd like to use that color in both plots. – David Oct 5 '15 at 17:30
• You can get the default color function for ContourPlot using ColorFunction->"M10DefaultDensityGradient" in your Plot3D. – N.J.Evans Oct 5 '15 at 18:38
• @N.J.Evans Nice suggestion. Thanks. The standard ContourPlot uses the idea dark color to light color as you go from low to high on the corresponding surface. One of students suggested GrayLevel, which gave a similar comparison. Anyone else have a favorite color that shows low to high in this situation? – David Oct 5 '15 at 21:30