# How to make a 3d surface/point plot with color based on a list

This is my data:

n = {0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195,
210, 225, 240, 255, 270, 285, 300, 315, 330};

x = {5.74, 5.23, 5.94, 3.41, 1.69, 9.43, 0.16, 11.83, 4.83, 3.44,
9.29, 6.32, 9.02, 5.7, 5.09, 3.07, 0.6, 0.23, 0.13, 0.61, 4.99,
3.15, 8.26};

y = {4.8, 3.38, 3.38, 1.38, 0.23, 9.95, 0.92, 5.92, 4.42, 5.89, 8.06,
5.69, 4.46, 3.96, 4, 1.99, 0.2, 0.23, 0.46, 1.96, 12.16, 5.9, 6.12};

z = {0.7, 3.8, 7.12, 10.52, 6.59, 0.43, 10.04, 0.45, 5.56, 4.76, 3.4,
0.88, 0.77, 3.59, 5.78, 8.24, 7.94, 10.38, 10.19, 9.8, 6.42, 4.69,
3.01};


Where f(n)=(x,y,z). So I want to plot x,y,z where every color represents a different value from list n.

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– user9660
Apr 21 '15 at 4:31

I think something like this is what you're after:

ListPlot3D[Transpose[{x, y, z}], ColorFunction -> Function[{x, y, z}, Hue[x]]]


Put whatever tickles your fancy into the function for the mapping of n to colors, and check the documentation for ColorFunction (and associated things like ColorFunctionScaling) to fine-tune.

• Normally we color Graphics 3D as a function (individual or combined ) of (x,y,z) right? That would perhaps be easier to define and display? Apr 21 '15 at 10:33
• I tried this: ListPointPlot3D[{x, y, z}, ColorFunction -> Function[{x, y, z}, Hue[z]]] But I am trying to make a 4D plot where color is the fourth dimension with every color representing a separate value from n. This statement gave me a lot of repeated colors Apr 22 '15 at 17:39

You can make an interpolating function from your data, that takes x, y, z as inputs and returns a color based on the matching value of n,

colorfunc =
Interpolation[{{#1, #2, #3}, #4} & @@@ Transpose[{x, y, z, n}],
InterpolationOrder -> 1]

ListPlot3D[Transpose[{x, y, z}],
ColorFunction -> (ColorData[{"Rainbow", MinMax@n}][
colorfunc[#1, #2, #3]] &), ColorFunctionScaling -> False,
PlotLegends ->
BarLegend[{ColorData[{"Rainbow", MinMax@n}], {0, 330}}]]