# Color function for ListPlot

I have an array of the following form {{a_n,b_n,c_n}} where n is quite large. I wish to plot a_n against b_n using Listplot with c_n specifying a ColorFunction perhaps Hue[] how would I go about this? Thank you

You could do that using Point and VertexColors:

data = {{1, 2, 0}, {2, 1, 0.5}, {3, 1.3, 0.6}, {4, 1.1, 0.8}};
Graphics[
Point[data[[All, ;; 2]],VertexColors -> (Hue /@ data[[All, 3]])],
Frame -> True,
ImageSize -> 400
]


This should be very good in terms of memory as you only have one Point object.

data = RandomReal[{0, 10}, {100, 3}];

rng = MinMax@data[[All, 3]];

Legended[
Graphics[
{AbsolutePointSize[5],
{ColorData["Rainbow"][Rescale[#[[3]], rng]],
Tooltip[Point[#[[1 ;; 2]]], #[[3]]]} & /@
data},
Frame -> True,
ImageSize -> 400,
FrameLabel -> (Style[#, 14] & /@ {"a", "b"})],
BarLegend[{"Rainbow", rng}]]


SeedRandom[1]
data = Round[RandomReal[5, {20, 3}], .01];


You can use your 3D data as input to BubbleChart with the option ColorFunction -> (Hue[#3] &):

BubbleChart[data, ColorFunction -> (Hue[#3] &),
BubbleSizes -> {.03, .03},
ChartLegends -> SwatchLegend[Hue /@ Rescale[Union[data[[All, -1]]]],
Union[data[[All, -1]]], LegendMarkers -> "Bubble"]]


Alternatively, you can wrap each point with List and ListPlot with the option PlotStyle:

ListPlot[List /@ data[[All, {1, 2}]],
PlotStyle -> (Hue /@ Rescale[data[[All, -1]]]),
BaseStyle -> PointSize[.03], ImageSize -> Medium, AspectRatio -> 1,
Frame -> True,
PlotLegends -> SwatchLegend[Union[styles], Union@data[[All, -1]],
LegendMarkers -> "Bubble"]]


• In terms of memory both are not very ideal: For a 100 points the bubblechart is 272664 bytes, the listplot 1086800, and my solution with vertexcolor just 9344 bytes. (i removed the legend from both). Mar 4, 2020 at 17:09
• @SHuisman, very good point. Got distracted with ListPlot and ColorFunction and missed the large n bit.
– kglr
Mar 4, 2020 at 17:12
• 'quite large' could mean 100 or 10^8 so I'm not sure about the importance… But both ListPlot and BubbleChart have a lot of overhead. Mar 4, 2020 at 17:20