# List of points with colors

I am working with a list of points on the plane, to each of them a natural number is assigned. It will be responsinble for the points' colors.

1) My first question is very easy: at initial moment I create list of random points and assign number 1 to all of them. I am doing this, probably, too ugly:

listOfPoints = RandomReal[{0,10}, {1000, 2}];
listOfPoints = Map[Append[#, 1] &, listOfPoints];
ListPlot[Map[Take[#, 2] &, listOfPoints]]


(Here colors still does not play.) Does exist a more elegant way?

2) And after I make some manipulations with some elements of the list, each manipulation will increase the number assigned to the element, i.e. its last coordinate. And then I would like to produce ListPlot in such a way that the color of a point {x,y,n} from the list will be, say,

Blend[{{Blue}, {Red}}, 1/n]


How do realize this?

First of all, it is better to store coordinates (real numbers) and integer numbers separately. You will benefit from packed arrays

n = 1000;
points = RandomReal[{0, 10}, {n, 2}];
numbers = ConstantArray[1, n];


After some data monipulation you will have different numbers. You can plot them easily with Point with specified VertexColors

numbers = RandomInteger[{1, 10}, n];

Graphics[Point[points, VertexColors -> (Blend[{Blue, Red}, 1/#] & /@ numbers)],
Frame -> True]


listOfPoints = MapIndexed[Join[#1, #2] &, RandomReal[{0, 10}, {1000, 2}]];
Graphics[{Blend[{Blue, Red}, 1/#3], Point[{#1, #2}]} & @@@ listOfPoints, Axes -> True]


Unfortunately, the blending very quickly results in basically all Blue (you can see the first point in red in the upper right). The problem is illustrated here:

Blend[{Blue, Red}, #] & /@ Table[1/n, {n, 1, 10}]


You might want to choose a different function to get a smoother transition from Red to Blue. Perhaps a linear interpolation:

listOfPoints = MapIndexed[Join[#1, #2] &, RandomReal[{0, 10}, {1000, 2}]];
Graphics[{Blend[{Blue, Red}, (1000 - #3 + 1)/1000], Point[{#1, #2}]} & @@@ listOfPoints, Axes -> True]


(I like MapIndexed, due to its flexibility: you can actually put the function directly in there as, for instance,

listOfPoints = MapIndexed[Join[#1, 1/#2] &, RandomReal[{0, 10}, {1000, 2}]];


but of course you can always do just

listOfPoints = Transpose@Join[Transpose@#, {Range[Length@#]}] &@ RandomReal[{0, 10}, {1000, 2}];


You might consider to use ListPointPlot3D for this kind of problem

points = 10;
colors = 3;

data =
Join[
RandomReal[{0, 10}, {points, 2}],
List /@ RandomInteger[{1, colors}, points],
2];

data // TableForm


plot =
ListPointPlot3D[
data,
PlotStyle -> PointSize @ Large,
ColorFunction -> "Rainbow"]


If you want you can use ColorFunction -> (Blend[{Red, Blue}, #3] &)

Let it look like a ListPlot

Show[
plot,
AspectRatio -> 1/GoldenRatio,
Axes -> {True, True, False},
Boxed -> False,
FaceGrids -> {{0, 0, 1}, {0, 0, 1}},
ViewPoint -> {0, 0, Infinity}]


Compare

ListPlot[Most /@ data, GridLines -> Automatic]


View it from front

Show[
plot,
Axes -> {False, True, True},
Boxed -> False,
FaceGrids -> {{1, 0, 0}, {1, 0, 0}},
ViewPoint -> {Infinity, 0, 0}]