Message Boards Message Boards

13
|
15599 Views
|
2 Replies
|
19 Total Likes
View groups...
Share
Share this post:

Placing a ContourPlot under a Plot3D

Placing a ContourPlot under a Plot3D could be a useful visualization. One strategy is quite simple: texture-map 2D plot on a rectangle under your 3D surface. I took a liberty with some styling that I like - you can always come back to yours.

contourPotentialPlot1 = ContourPlot[-3600. h^2 + 0.02974 h^4 - 5391.90 s^2 + 
   0.275 h^2 s^2 + 0.125 s^4, {h, -400, 400}, {s, -300, 300}, 
 PlotRange -> {-1.4*10^8, 2*10^7}, Contours -> 15, Axes -> False, 
 PlotPoints -> 30, PlotRangePadding -> 0, Frame -> False, ColorFunction -> "DarkRainbow"];

potential1 = Plot3D[-3600. h^2 + 0.02974 h^4 - 5391.90 s^2 + 0.275 h^2 s^2 + 
    0.125 s^4, {h, -400, 400}, {s, -300, 300}, 
   PlotRange -> {-1.4*10^8, 2*10^7}, ClippingStyle -> None, 
   MeshFunctions -> {#3 &}, Mesh -> 15, MeshStyle -> Opacity[.5], 
   MeshShading -> {{Opacity[.3], Blue}, {Opacity[.8], Orange}}, Lighting -> "Neutral"];

level = -1.2 10^8; gr = Graphics3D[{Texture[contourPotentialPlot1], EdgeForm[], 
Polygon[{{-400, -300, level}, {400, -300, level}, {400, 300, level}, {-400, 300, level}}, 
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}, Lighting -> "Neutral"];

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

enter image description here

You can see I used PlotRangePadding -> 0 option in ContourPlot. It is to remove white space around the graphics to make texture mapping more precise. If you need utmost precision you can take another path. Extract graphics primitives from ContourPlot and make them 3D graphics primitives. If you need to color the bare contours - you could replace Line by Polygon and do some tricks with FaceForm based on a contour location.

level = -1.2 10^8;
pts = Append[#, level] & /@ contourPotentialPlot1[[1, 1]];
cts = Cases[contourPotentialPlot1, Line[l_], Infinity];
cts3D = Graphics3D[GraphicsComplex[pts, {Opacity[.5], cts}]];

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

enter image description here

POSTED BY: Vitaliy Kaurov
2 Replies

Vitaliy & Michael, Thanks very much for your excelent suggestions! I am very gratefull! Christos

Here's an alternative way in which the "contour plot" takes its contours styling directly from the plot and its mesh lines (which need to be from MeshFunctions -> {#3 &}):

Show[
 potential1,
 DeleteCases[
  potential1 /. GraphicsComplex[pts_, rest___] :>
    GraphicsComplex[
     PadRight[pts[[All, ;; 2]], {Automatic, 3}, 
      Rescale[PlotRange[potential1][[3]], (* the whole Rescale[..] code can be replaced by any number/level *)
        {0, 1},
        {-0.05, 1}                        (* project 5% lower than original plot range - change as desired *)
        ][[1]]],
     rest],
  Verbatim[Rule][VertexNormals, _], Infinity],
 PlotRange -> All]

enter image description here

POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract