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.

  • $\begingroup$ 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? $\endgroup$
    – user49048
    Jan 14, 2022 at 0:48
  • $\begingroup$ 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. $\endgroup$
    – Parviz
    Jan 14, 2022 at 1:44
  • $\begingroup$ hi again. I attempted something. if you don't find it helpful, let me know and I will remove the answer $\endgroup$
    – user49048
    Jan 14, 2022 at 2:19
  • $\begingroup$ This may work GathetBy[data,Last] and plot the new data set. $\endgroup$ Jan 14, 2022 at 13:40

2 Answers 2


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

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:

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

enter image description here


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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.