2

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.

David
  • 14,883
  • 4
  • 44
  • 117
  • 1
    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 05 '15 at 16:39

1 Answers1

2
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"]}]

enter image description here

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78
  • 2
    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 05 '15 at 15:56
  • @N.J.Evans Can you show how you do this with an answer? Thank you. – David Oct 05 '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 05 '15 at 17:30
  • 2
    You can get the default color function for ContourPlot using ColorFunction->"M10DefaultDensityGradient" in your Plot3D. – N.J.Evans Oct 05 '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 05 '15 at 21:30
  • Someone asked a question about perceptual color schemes awhile back. 64513 I usually use the color scheme I contributed. It maps to grayscale when printed on a black and white printer, and has some knobs to turn if you need to distinguish two images in a talk or something. – N.J.Evans Oct 05 '15 at 22:18