# Mapping Contour Plot onto ListPlot3D (or by using color variations) [closed]

I am trying to overlay a contour plot I have created on a ListPlot3D graph. I have seen a few questions answered on this website that answer my basic question. However, the contour plot I need to use cannot be simply applied to a table, so the ListInterpolation function is not of use to me. Is there a way to get around this problem? Right now, I have used a method provided in this question, Using a ListDensityPlot to map color onto a ListPlot3D graph (using an image rather than the actual function to graph) but the resulting graphic (cp5) is slighly blurry, not oriented correctly, and not to the perfect size (see the function below).

ListPlot3D[gs5Matrix5, TextureCoordinateFunction -> ({#1, #2} &),
PlotStyle -> Texture[cp5], PlotRange -> All,
BoxRatios -> {1, 1, 1/2}, Mesh -> None, ImagePadding -> None]

In addition, gs5Matrix gives an array of coordinates (i.e. {{1,2,3}, {4,5,6}, {..}…}. I found this to be the easiest way to represent the points seeing as the second coordinate spacing (which has to do with unevenly spaced cosine values) makes it difficult to show in a table.

The contour function is as follows:

potentialM5[r_, Î¸_] :=
Module[{x, n, Ïµ, V},
x = r/Rm5[Î¸, Îº] /. m5values;
n = m5[Î¸, Î¾] + Î³*(x – 1) /. m5values;
Ïµ = Ïµ0 + dÏµ1*f[Î¸, Î»] + dÏµ2*g[Î¸] /. m5values;
V = Ïµ/(n – 6)*(6*x^-n – n*x^-6);
V
]

cp5 = ContourPlot[
potentialM5[r, Î¸], {Î¸, 0, 180}, {r, 3, 6},
Contours -> contours]

Rm5[Î¸_, v_] = Rm0 + dR1*f[Î¸, v] + dR2*g[Î¸];
g[Î¸_] = If[Î¸ >= 90, Cos[(Î¸*Ï€)/180]^2, 0];
m5[Î¸_, v_] = m0 + dm*f[Î¸, v];
m5values = {Ïµ0 -> 180.51, dÏµ1 -> -79.35,
dÏµ2 -> 34.0, Î» -> 4.04, Rm0 -> 4.0093,
dR1 -> -.1234, dR2 -> -.160, Îº -> 12.11, m0 -> 22.39,
dm -> -9.93, Î¾ -> 17.25, Î³ -> 9.0};
f[Î¸_, v_] = 1 – (1/2 (1 + Cos[(Î¸*Ï€)/180]))^v;

Any help would be greatly appreciated.

Update: Since my g5Matrix5 is too challenging to define here, I have devised a simpler example whose answer should provide me with an answer to my own question. Below are the equations for both the contour plot as well as the ListPlot3D.

ContourPlot[Sin[x]^2 + 2 y, {x, 0, 2 Ï€}, {y, 0, 4}];

values = {{0, 0, 0.2`}, {0, 1, 0.3`}, {0, 3.5`, 0.43`}, {0, 4, 0.2`},
{(2 Ï€)/3, 0, 0.38`}, {(2 Ï€)/3, 1, 0.45`}, {(2 Ï€)/3, 3.5`, 0.25`},
{(2 Ï€)/3, 4, 0.1`}, {(4 Ï€)/3, 0, 0.37`}, {(4 Ï€)/3, 1, 0.4`},
{(4 Ï€)/3, 3.5`, 0.5`}, {(4 Ï€)/3, 4, 0.2`}, {2 Ï€, 0, 0.2`},
{2 Ï€, 1, 0.5`}, {2 Ï€, 3.5`, 0.35`}, {2 Ï€, 4, 0.22`}};

As you can see, the y-values are spaced unevenly

=================

=================

4

=================

You can strip the frame and padding from the contour plot and the OP’s approach seems to work.

cp5 = ContourPlot[Sin[x]^2 + 2 y, {x, 0, 2 Ï€}, {y, 0, 4}];

values = {{0, 0, 0.2`}, {0, 1, 0.3`}, {0, 3.5`, 0.43`}, {0, 4, 0.2`},
{(2 Ï€)/3, 0, 0.38`}, {(2 Ï€)/3, 1, 0.45`}, {(2 Ï€)/3, 3.5`, 0.25`},
{(2 Ï€)/3, 4, 0.1`}, {(4 Ï€)/3, 0, 0.37`}, {(4 Ï€)/3, 1, 0.4`},
{(4 Ï€)/3, 3.5`, 0.5`}, {(4 Ï€)/3, 4, 0.2`}, {2 Ï€, 0, 0.2`},
{2 Ï€, 1, 0.5`}, {2 Ï€, 3.5`, 0.35`}, {2 Ï€, 4, 0.22`}};

lpcp5 = ListPlot3D[values, TextureCoordinateFunction -> ({#1, #2} &),
PlotStyle ->
PlotRange -> All, BoxRatios -> {1, 1, 1/2}, Mesh -> None,

GraphicsRow[{
cp5, Show[lpcp5, ViewPoint -> {0, 0, Infinity}, ImagePadding -> {{15, 0}, {15, 0}}]}]

I may have misunderstood but avoiding the overlays (and using values:

f[x_, y_] := Sin[x]^2 + 2 y
mx = Maximize[{f[x, y], 0 < x < 2 Pi, 0 < y < 4}, {x, y}] mn = Minimize[{f[x, y], 0 < x < 2 Pi, 0 < y < 4}, {x, y}] cont = Range[0, 9, 1]; contc[col_] := ColorData[col][#/9] & /@ cont; Manipulate[ ListPlot3D[values, MeshFunctions -> {Sin[#1]^2 + 2 #2 &},
Mesh -> {cont}, MeshShading -> contc[color]], {color,

I drew a contour plot by defining Contours as 5,If it looks something like what your are
expecting we may be on the right track.However I can’t do the List Plot because
gs5Matrix5 is not defined.

Rm5[Î¸_, v_] = Rm0 + dR1*f[Î¸, v] + dR2*g[Î¸];

g[Î¸_] = If[Î¸ >= 90, Cos[(Î¸*Ï€)/180]^2, 0];
m5[Î¸_, v_] = m0 + dm*f[Î¸, v];
m5values = {Ïµ0 -> 180.51, dÏµ1 -> -79.35,
dÏµ2 -> 34.0, Î» -> 4.04, Rm0 -> 4.0093,
dR1 -> -.1234, dR2 -> -.160, Îº -> 12.11, m0 -> 22.39,
dm -> -9.93, Î¾ -> 17.25, Î³ -> 9.0};
f[Î¸_, v_] = 1 – (1/2 (1 + Cos[(Î¸*Ï€)/180]))^v;

potentialM5[r_, Î¸_] :=
Module[{x, n, Ïµ, V},
x = r/Rm5[Î¸, Îº] /. m5values;
n = m5[Î¸, Î¾] + Î³*(x – 1) /. m5values;
Ïµ = Ïµ0 + dÏµ1*f[Î¸, Î»] +
dÏµ2*g[Î¸] /. m5values;
V = Ïµ/(n – 6)*(6*x^-n – n*x^-6);
V]

cp5 = ContourPlot[
potentialM5[r, Î¸], {Î¸, 0, 180}, {r, 3, 6},
Contours -> 5]

This helps me with plotting the countour, but I did have this portion of my problem solved. I am looking for a way to map this contour on top of the ListPlot3D. I have updated my initial question with a simplified answer that has values for the ListPlot3D as well as the contour. Thanks!
– user24717
Jan 15 ’15 at 18:10

Try this:

ListPlot3D[values, MeshFunctions -> {Function[{x, y, z}, Sin[x]^2 + 2 y]}]

This produces a pretty low-quality output for the given example, but the more points you have in the ListPlot the more points are used in calculating the contours for the mesh.

For example:

ListPlot3D[
Join @@ Table[{x, y, Abs[Sin[x + I y]]}, {x, -Pi, +Pi,
Pi/20.}, {y, -1, +1, 0.05}],
MeshFunctions -> {Function[{x, y, z}, Arg[Sin[x + I y]]]},
BoxRatios -> Automatic]

(Plotting the absolute value of the complex Sin function, and overlaying contours of the complex argument.)

I just noticed that you specified the contour values with Contours -> contours, in this case you can use Mesh -> {contours}.
– 2012rcampion
Jan 28 ’15 at 2:48