# Projection of 3d data to 2d with ListPlot and color function

This question is related to this one or that.

SeedRandom[1];

data = RandomInteger[100, {100, 3}];

x = data[[All,1]];
y = data[[All,2]];
z = data[[All,3]];


I want to use ListPlot to show x versus y as points whereby the color should represent z.

How can I use a certain color map like TemperatureMap or my own color table?

(* e.g. own color table *)
number = Length@z;
colTable = {Table[{Blend[{Blue, Green, Yellow, Red}, i]}, {i, 1/number, 1, 1/number}]};
colTable = Flatten[colTable];


Blatantly stealing three-quarters of @ubpdqn's answer (particularly the rescaled ColorFunction), you can use Style to get it working in ListPlot, as requested by the OP:

SeedRandom[1];
data = RandomInteger[100, {100, 3}];

cf = ColorData["TemperatureMap", Rescale[#, MinMax[data[[All, 3]]]]] &;
Row[{ListPlot[Style[{#[[1]], #[[2]]}, cf[#[[3]]]] & /@ data,
PlotStyle -> PointSize[Large], ImageSize -> 350],
BarLegend[{cf[#] &, {0, 100}}, Range[0, 100, 10]]}]


And, of course, you can change out "TemperatureMap" for any other colour scheme.

In such cases, I go with Graphics.

data = RandomInteger[100, {100, 3}];

{z1, z2} = MinMax[data[[All,3]]];
Grid[
{{Graphics[{PointSize[Large], Hue[(#[[3]] - z1)/(z2 - z1)/2 + 0.5],
Point[#[[1 ;; 2]]]} & /@ data, Frame -> True],
BarLegend[{Hue, {z1, z2}}]}}]


clfun[x_] := Blend[{Blue, Green, Yellow, Red}, x]
{z1, z2} = MinMax[data[[All,3]]];
Grid[
{{Graphics[{PointSize[Large], clfun[(#[[3]] - z1)/(z2 - z1)/2 + 0.5],
Point[#[[1 ;; 2]]]} & /@ data, Frame -> True],
BarLegend[{clfun[#] &, {0, 1}}, Ticks -> {{0, z1}, {1, z2}}]}}]


To use a TemperatureMap

clfun[x_] := ColorData["TemperatureMap"][x]

• This is great, thanks a lot ... how can I to use ListPlot because there I can add PlotRange and other keywords which Graphics does not have. For the solution of the custom colormap I get the info: "Ticks is not an option of BarLegend". Is it possible to access the colors of TemperatureMap?
– mrz
Oct 18, 2017 at 9:56
• You can use PlotRage with Graphics. Ticks appears in red with BarLegend but it works. Which version you are using. There might be some problem with old versions. Oct 18, 2017 at 10:05
• Thanks for the solutions with the color map. I am using 11.2 -> PlotRange is possible. I thought that ListPlot is usally used to plot data intead of using Graphics?
– mrz
Oct 18, 2017 at 10:32
• well, deep inside ListPlot is a Graphics ;). You are right, it is more convenient to use ListPlot or ListLinePlot while plotting data due to its inbuilt options. You can do the same thing using Graphics but it takes more efforts and commands. Oct 18, 2017 at 11:18

You could also use "TemperatureMap" is in-built color scheme,e.g.:

cf = ColorData["TemperatureMap", Rescale[#, MinMax[data[[All, 3]]]]] &;
Row[{Graphics[{cf@#3, PointSize[0.04],
Tooltip[Point[{#1, #2}], #3]} & @@@ data, Frame -> True,
ImageSize -> 200],
BarLegend[{cf[#] &, {0, 100}}, Range[0, 100, 10]]}]


• You can use that ColorFunction in ListPlot, too, as the OP seems to want: ListPlot[Style[{#[[1]], #[[2]]}, ColorData["TemperatureMap", Rescale[#[[3]], MinMax[data[[All, 3]]]]]] & /@ data, PlotStyle -> PointSize[Large]]. Oct 18, 2017 at 10:56
• @aardvark2012 very good point...put it is an answer as it uses ListPlot :) Oct 18, 2017 at 11:00
• @aardvark2012: yes please ... I would like to see also the solutions with ListPlot.
– mrz
Oct 18, 2017 at 11:02