# Using a ListDensityPlot to map color onto a ListPlot3D graph

I have a 3 column list of data points. The first two columns correspond to x and y coordinates, with data points creating a surface in the z direction from column 3. This gives me a nice wavy surface.

I have a separate file of corresponding error values (chi) which amounts to a similar 3 columns: same x and y coordinates with chi values for each point in my data file. With this file, I've created a very nice (read: adequate) density plot, to show in 2 dimensions, via shading, the variation of chi across the parameter space.

What I'd LIKE to do, is then use this 2D representation to shade the 3D plot, sort of like a "hot" and "cold" graph so I can visualize where the errors tend to be highest and lowest, while easily associating them with my data.

Any ideas? Much appreciated!

Edit: Adding code and plots for clarity.

ListDensityPlot[gchi[[All, {1, 2, 3}]],ColorFunction -> "DarkRainbow"]


These are the colors I'd like plotted on the following 3D plot (of different values). The colors vary by value from blue(low) to red(high).

ListPlot3D[{gband[[All, {1, 2, 3}]]}, PlotRange -> Full, Mesh -> 6,ColorFunction -> Function[{gchix, gchiy, gchiz}, Hue[gchiz]]]


This is the graph of "found" values for the functions I'm fitting. They're over the same space (x,y) coords as the density plot above, and here, the z components represent data points.

I'd like to color this 3D graph by a projection of the 2D density plot (of different values z, same values x,y) onto the rendered surface. Arbitrary color scheme, I just want it to vary by a separate function determined by a separate list of values.

-
Have you tried using a different ColorFunction on 'ListPlot3D? –  Eli Lansey Oct 26 '12 at 2:36
I've used a few built in ColorFunction's on my ListPlot3D. The trouble is, I don't just want a pretty colored graph, based (perhaps) on the x,y, or z values of that graph; I want it colored by a different function entirely, effectively a 4th coordinate represented. –  Ben Strickland Oct 26 '12 at 2:42
Perhaps I should clarify and ask how to create a new color function in x and y, based on the values of z, then use this ColorFunction to color a separate ListPlot3D. –  Ben Strickland Oct 26 '12 at 2:44
I'm pretty sure there's an example of exactly that in the help file. –  Eli Lansey Oct 26 '12 at 2:50
You might find Heike's answer to a similar question useful. –  kguler Oct 26 '12 at 6:30

As an alternative to using ColorFunction, one can also use PlotStyle ->Texture[img] where img can be a 2D graphics using some features of the input data.

Few examples using data with a similar structure to the one described in OP's question:

 datatable =Table[{Sin[j + i] + .05 RandomReal[], RandomReal[]},
{i, -2, 2, 0.1}, {j, -2, 2, 0.1}];

options =  Sequence[ColorFunction -> "TemperatureMap", Frame -> False,
PlotRangePadding -> None, ImagePadding -> None, ImageSize -> 300, Mesh -> None];
texture1 = ArrayPlot[datatable[[All, All, 2]], options];
texture2 = ListDensityPlot[datatable[[All, All, 2]], options];
lstplt1 = ListPlot3D[datatable[[All, All, 1]], BoxRatios -> 1, Mesh -> None,
TextureCoordinateFunction -> ({#1, #2} &),
TextureCoordinateScaling -> True, PlotStyle -> Texture[texture1]  ];
lstplt2 = ListPlot3D[datatable[[All, All, 1]], BoxRatios -> 1, Mesh -> None,
TextureCoordinateFunction -> ({#1, #2} &),
TextureCoordinateScaling -> True, PlotStyle -> Texture[texture2]];
Grid[{{texture1, lstplt1}, {texture2, lstplt2}}]


Another example using the cropped version of the 2D image in OP's question:

 ListPlot3D[Table[Sin[j + i], {i, -3, 3, 0.05}, {j, -3, 3, 0.05}],
TextureCoordinateFunction -> ({#1, #2} &), PlotStyle -> Texture[img],
PlotRange -> All, BoxRatios -> {1, 1, 1/2},
Mesh -> None, ImagePadding -> None]


-
Thanks for the response. I really appreciate it! I learned plenty from your code--aside from your specific response. I think I'll use the other method, as it seems more in the way I'd originally wanted to solve the problem. –  Ben Strickland Oct 26 '12 at 7:14
@Ben, my pleasure. Welcome to mma.se. –  kguler Oct 26 '12 at 7:23

DensityPlot just colorizes your array by choosing colors for scalar values and plot the array like an image. The ColorFunction option of ListPlot3D or Plot3D does basically the same with the difference, that it uses the height values of the function you plot as indicator for the color.

What you want is close: You want to use the height-values of another array as indicator for the color. Therefore, one approach would be to interpolate your first array to make a function from it and then use it inside the ColorFunction of your ListPlot3D:

densFunc =
ListInterpolation[
Table[Sin[x y]^2, {y, 0, Pi, 0.1}, {x, 0, Pi, 0.1}], {{0, 1}, {0, 1}}];


The inside Table is the equivalent of your gchi array. Now you can set up the ListPlot3D (I use Plot3D here, so spare the creating of a second array)

Plot3D[Exp[-(x^2 + y^2)], {x, -2, 2}, {y, -2, 2},
ColorFunction ->
Function[{x, y}, ColorData["TemperatureMap", densFunc[x, y]]],
PlotPoints -> 50]


• when your gchi data is not on a regular grid, then you cannot simply use ListInterpolation.
• Note, that you directly use densFunc inside ColorData which does expect values between [0,1]. So if the z-values of your array you want to use for colorization is not normalize, you should take care of this.
• Be aware that per default parameters to ColorFunction (x,y,z) are normalized to [0,1]. That's why my above example works although my interpolation function is only defined in the unit-square and I use Plot3D in larger region. Look at the option ColorFunctionScaling`.