# Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this?

-
Could you post what you have tried and maybe a sample of your data? – s0rce Feb 22 '13 at 18:20
Probably can find your answer here: mathematica.stackexchange.com/questions/6521/… – s0rce Feb 22 '13 at 18:24
another post might be helpful:mathematica.stackexchange.com/questions/19575/… – halmir Feb 22 '13 at 18:41

Here a another possible way to visualize 4D data:

data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]},
{x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1];


You can use the function Point along with VertexColors. Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer.

Graphics3D[
Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]],
Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]


-
This is a good solution. I only need to figure out how to normalize the Hue (my wavelength data goes from 530 to 640) Thanks for the quick help. – J-P Feb 22 '13 at 20:04
You should take a look at the useful function Rescale: Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue[Rescale[#,{530,640}]] /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}] – chuy Feb 22 '13 at 22:39
IS there a way to plot the function directly, without generating the points? – Andrei Kucharavy May 23 '14 at 5:15

You can try the following approach. Let's first generate some 4D data:

ndata = 100;
data = Transpose[{RandomReal[{-1, 1}, ndata],
RandomReal[{-1, 1}, ndata], RandomReal[{0, 10}, ndata],
RandomReal[{400, 800}, ndata]}];


Now we use the first three columns as $x$, $y$ and $z$ coordinates, whereas the 4th column specifies the color of each point. The color range is specified via the Blend function that specifies that a value of 400 should correspond to Darker[Green], a value of 600 to Yellow and a value of 800 to Red. All other values are blended colors.

ListPointPlot3D[List /@ data[[All, {1, 2, 3}]],
PlotStyle -> ({PointSize[Large],
Blend[{{400, Darker[Green]}, {600, Yellow}, {800,
Red}}, #1]} & /@ Flatten[data[[All, {4}]]])]


-
This also works. Thanks for the help. Too bad I can't select 2 answers as solution. – J-P Feb 22 '13 at 20:06