# Plotting a data set

I have data set like this (x , y , n) n is the number from 0 to 12 I want to plot this data set but I want to the color of each point be base on the third column. For example if I have 0 in third column get red point on my graph and for 2 get blue and so far.

• it is not very clear to me what sort of list you have. is x a list and y a list and n just a number? or do you have a list of three lists? can you provide some data explicitly?
– user49048
Jan 14, 2022 at 0:48
• I have a coordinate (x,y) which each coordinate is tagged with a number (between 0-12) I want to plot all of those points but for each point have different color depend on the number in third column. Jan 14, 2022 at 1:44
• hi again. I attempted something. if you don't find it helpful, let me know and I will remove the answer
– user49048
Jan 14, 2022 at 2:19
• This may work GathetBy[data,Last] and plot the new data set. Jan 14, 2022 at 13:40

I assume your data consist of triplets: {x,y,color}. For an example, we create some data:

SeedRandom[10];
dat = RandomInteger[{0, 12}, {20, 3}];


We use ListPlot to display the data and color the points using ColorFunction. As ColorFunction only receive {x,y}, we need to look up the third element of the triple:

SeedRandom[10];
dat = RandomInteger[{0, 12}, {20, 3}];
ListPlot[dat[[All, 1 ;; 2]],
ColorFunction -> (Hue[Cases[N@dat, {#1, #2, _}][[1, 3]]/12] &),
ColorFunctionScaling -> False]


The data points in the x- and y-axes.

x = {1, 2, 3, 4};
y = {1, 2, 3, 4};


Create the list to be plotted

z = Thread[{x, y}]


One way:

ListPlot[{#} & /@ z, PlotStyle -> list2]


A second way:

ListPlot[{{Style[z[[1]], Green]}, {Style[z[[2]], Purple]}, {Style[
z[[3]], Red]}}, PlotStyle -> PointSize[0.02]]


A third way:

Graphics[Prepend[Riffle[list2, Point /@ list1], PointSize[0.03]],
Frame -> True]