6
$\begingroup$

I'm trying to draw, for a series of multivariables functions, both the surface plot and the level curves. I am using the following code:

contourPotentialPlot1 = 
ContourPlot[Abs[x] + Abs[y], {x, -3, 3}, {y, -3, 3}, 
PlotRange -> {-5, 15}, Contours -> 15, Axes -> False, 
PlotPoints -> 30, PlotRangePadding -> 0, Frame -> False, 
ColorFunction -> "BlueGreenYellow"];

potential1 = 
Plot3D[Abs[x] + Abs[y], {x, -3, 3}, {y, -3, 3}, 
PlotRange -> {-5, 5}, ClippingStyle -> None, 
MeshFunctions -> {#3 &}, Mesh -> 15, MeshStyle -> Opacity[.5], 
MeshShading -> {{Opacity[.9], LightBlue}, {Opacity[1.9], 
  LightBlue}}, Lighting -> "Neutral"];

level = -5; gr = 
Graphics3D[{Texture[contourPotentialPlot1], EdgeForm[], 
Polygon[{{-3, -3, level}, {3, -3, level}, {3, 3, level}, {-3, 3, 
  level}}, 
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}, 
Lighting -> "Neutral"];

Show[potential1, gr, PlotRange -> All, BoxRatios -> {1, 1, .6}, 
FaceGrids -> {Back, Left}]

The output is the following: 

enter image description here

How can I modify the code to visualize a "good" reverse pyramid (which is what comes out from the plot of $z = |x| + |y|$)? From the above one it's not clear that it's a pyramid.

Thank you!

I tried to modify the BoxRations parameters, and with something like {1, 1, 2.6} the effect is a bit better, but still it looks like something forces. I would like to observe a "more pyramidical" plot :D

$\endgroup$
0

2 Answers 2

9
$\begingroup$

You can use RegionFunction and give it a region of interest over which you want to plot (ie. rotated square in your case).

regFunc[x_, y_, z_] := Abs[x] + Abs[y] < 3;

potential1 = 
 Plot3D[Abs[x] + Abs[y], {x, -3, 3}, {y, -3, 3}, PlotRange -> {-5, 5},
   RegionFunction -> regFunc, ClippingStyle -> None, 
  MeshFunctions -> {#3 &}, Mesh -> 15, MeshStyle -> Opacity[.5], 
  MeshShading -> {{Opacity[.9], LightBlue}, {Opacity[1.9], 
     LightBlue}}, Lighting -> "Neutral"]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you so much!!! $\endgroup$
    – Heidegger
    Feb 23 at 21:46
6
$\begingroup$
Clear["Global`*"];
level = 4;    
potential1 = Plot3D[Abs[x] + Abs[y]
   , {x, -4, 4}, {y, -4, 4}
   , PlotRange -> {-5, 5}
   , ClippingStyle -> None
   , MeshFunctions -> {#3 &}
   , Mesh -> 15
   , MeshStyle -> Opacity[.5]
   , MeshShading -> {
     {Opacity[.9, LightBlue]}
     , {Opacity[0.5, LightBlue]}
     }
   , Lighting -> "Neutral"
   , ClipPlanes -> {InfinitePlane[
      {{0, 0, level}, {0, 1, level}, {1, 0, level}}]}
   , ClipPlanesStyle -> Opacity[.4, Gray]
   , BoxRatios -> Automatic
   ];

scp = SliceContourPlot3D[Abs[x] + Abs[y], {z == -level}
   , {x, -4, 4}, {y, -4, 4}, {z, -5, 5}
   , PlotRange -> {{-4, 4}, {-4, 4}, {-5, -5}}
   , Contours -> Range[0, 6]
   , ColorFunction -> "BlueGreenYellow"
   ];

Show[potential1, scp, PlotRange -> All, FaceGrids -> {Back, Left}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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