# 2D ListPlot with separate color function

Suppose a data array of the form {{x1,y1,z1},{x2,y2,z2}...}, is it possible to use ListPlot where x,y specify the point position and z (Hue[z]) specify the color of each point?

• yes, use the ColorFunction see ref/ListPlot3D under Color by scaled x, y, and z values. there is example there to do this. – Nasser Jan 3 '14 at 5:48
• @Nasser Yes, I know that can be done with 3D list plots, but I want a 2D plot where z is only used for coloring – egwene sedai Jan 3 '14 at 5:58
• So you only want to plot the {x,y} part of the list? and use the z component for coloring of the point? I miss-understood. – Nasser Jan 3 '14 at 6:07

If you really must use ListPlot and not Graphics as Ubpdqn showed, then here is a hack.

The problem is that ColorFunction for 2D takes only {x,y}. One way is to get the z value yourself from the data. But for this you need the current index.

So simply make an index, set it to zero, and increment it each time the ColorFunction is called. Like this. Notice, must use Joined -> True for this to work.

data = RandomReal[{0, 1}, {40, 3}];
n = 0; (*make sure to set this to zero before each call*)
ListPlot[data[[All, {1, 2}]],PlotStyle->Directive[PointSize[Large]],Joined -> True,
ColorFunction -> Function[{x, y}, Hue[data[[++n, 3]]] ]] /. Line[a__] :> Point[a] • Thank you for the solution. How could I use a certain color map like "TemperatureMap or my own color table: number = Length@data[[All,3]]; colTable = {Table[{Blend[{Blue, Green, Yellow, Red}, x]}, {x, 1/number, 1, 1/number}]}; colTable = Flatten[colTable]; – mrz Oct 18 '17 at 9:01

You could achieve this using Graphics, for example:

data = RandomReal[{0, 1}, {100, 3}];
Graphics[{Hue[#3], PointSize[0.02], Point[{#1, #2}]} & @@@ data,
Axes -> True] 