# Providing a color function for ListPointPlot3D

Is there a way to write ListPointPlot3D expression, so when given a list of points, the the color of the points plotted is a function of the index/element number of the list?

Suppose list contains the points to be plotted and the color function is Blend[{Yellow, Brown}, n], with n being the index a point in list, then list[[1]] should be yellow and list[[-1]] should be brown.

I feel like I'm almost there, but I cannot manage to combine the pieces, hope someone can help me!

-

Using VertexColors is efficient if there are many points.

SeedRandom[1];
pts = RandomReal[1, {100, 3}];


Post-process ListPointPlot3D:

ListPointPlot3D[pts, PlotStyle -> PointSize[Large]] /.
Point[pp_] :>
Point[pp, VertexColors -> (Blend[{Yellow, Brown}, #] & /@ Rescale@Range@Length[pp])]


Or directly with Graphics3D:

Graphics3D[{PointSize[Large],
Point[pts, VertexColors -> (Blend[{Yellow, Brown}, #] & /@ Rescale@Range@Length[pts])]},
BoxRatios -> {1, 1, 0.4}, Axes -> True
]


In both cases I get indistinguishable graphics:

-

Doing this with ListPointPlot3D is not very straightforward, but do look at the answer by m_goldberg.

However, ListPointPlot3D is trivial to re-implement in terms of graphics primitives. Here's one way to colour based on index:

pts = RandomReal[1, {10, 3}];

Graphics3D[
{PointSize[Large],
MapIndexed[{Blend[{Yellow, Brown}, First[#2]/Length[pts]], Point[#1]} &, pts]}
]


The second argument of Blend must be a number between 0 and 1, so we needed to divide the index by the total number of points.

-

In V10, with the new association objects, it is easy to implement what you want with ListPointPlot3D What is needed is a hash map (which is my mental image of an association) that maps your list of points into index values for Blend. This can be built with AssociationThread. Consider

pts = RandomInteger[99, {100, 3}];
indxs = AssociationThread[pts, Range @ Length @ pts/Length @ pts];
ListPointPlot3D[pts,
PlotStyle -> {PointSize[Large]},
ColorFunctionScaling -> False,
ColorFunction -> (Blend[{Yellow, Brown}, indxs[{##}]] &)]


-
Fair enough, removed that remark. And +1 :) – Szabolcs Jul 27 '14 at 3:43
pts = RandomReal[1, {10, 3}];

ListPointPlot3D[pts,
PlotStyle -> PointSize[Large],
BoxRatios -> {1, 1, 1},
PlotRange -> {{0, 1}, {0, 1}, {0, 1}},
ColorFunction ->
Function[{x, y, z},
Blend[{Yellow, Brown},
Position[pts, {x, y, z}][[1, 1]]/Length[pts]]],
ColorFunctionScaling -> False]


-
SeedRandom[1];
pts = RandomReal[1, {100, 3}];

i = 1;
ListPointPlot3D[List /@ pts, BaseStyle -> PointSize[Large],
PlotStyle -> Table[Blend[{Yellow, Brown}, i++/Length[pts]], {Length[pts]}]]
`

-