3
$\begingroup$

This code adapted from Placing a ContourPlot under a Plot3D works pretty well.

u[x_, y_] := x^.5 y^.5
contour = 
 ContourPlot[u[x, y], {x, 0, 1}, {y, 0, 1}, PlotRange -> {0, 1}, 
  Axes -> False, Contours -> 15, PlotPoints -> 50, 
  PlotRangePadding -> 0, ColorFunction -> "Aquamarine"]
potential1 = 
 Plot3D[u[x, y], {x, 0, 1}, {y, 0, 1}, PlotRange -> {0, 1}, 
  ClippingStyle -> None, MeshFunctions -> {#3 &}, Mesh -> 15, 
  MeshStyle -> Opacity[.5], 
  MeshShading -> {{Opacity[.3], Blue}, {Opacity[.8], LightBlue}}, 
  PlotRange -> {Automatic, Automatic, {min, 2}}, Lighting -> "Neutral"]
Show[potential1, 
 Graphics3D[contour[[1]] /. {x_Real, y_Real} :> {x, y, 0}], 
 BoxRatios -> {1, 1, 0.6}, FaceGrids -> {Back, Left}]

Here is the outcome:

enter image description here

I wonder how to reuse the color function on the contour plot to have identical colors.

$\endgroup$
  • $\begingroup$ min is missing. $\endgroup$ – corey979 Jan 11 '17 at 18:52
  • $\begingroup$ As much fo me min = 0 $\endgroup$ – cyrille.piatecki Jan 11 '17 at 19:43
6
$\begingroup$

In contour, instead of ColorFunction place ContourShading -> {{Opacity[.3], Blue}, {Opacity[.8], LightBlue}}:

u[x_, y_] := x^.5 y^.5
contour = 
  ContourPlot[u[x, y], {x, 0, 1}, {y, 0, 1}, PlotRange -> {0, 1}, 
   Axes -> False, Contours -> 15, PlotPoints -> 50, 
   PlotRangePadding -> 0, 
   ContourShading -> {{Opacity[.3], Blue}, {Opacity[.8], 
      LightBlue}}];
potential1 = 
  Plot3D[u[x, y], {x, 0, 1}, {y, 0, 1}, PlotRange -> {0, 1}, 
   ClippingStyle -> None, MeshFunctions -> {#3 &}, Mesh -> 15, 
   MeshStyle -> Opacity[.5], 
   MeshShading -> {{Opacity[.3], Blue}, {Opacity[.8], LightBlue}}, 
   PlotRange -> {Automatic, Automatic, {min, 2}}, 
   Lighting -> "Neutral"];
Show[potential1, 
 Graphics3D[contour[[1]] /. {x_Real, y_Real} :> {x, y, 0}], 
 BoxRatios -> {1, 1, 0.6}, FaceGrids -> {Back, Left}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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