Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
up vote 4 down vote accepted

Using VertexColors is efficient if there are many points.

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:

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

In both cases I get indistinguishable graphics:

Mathematica graphics

share|improve this answer

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}];

  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.

share|improve this answer

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];
  PlotStyle -> {PointSize[Large]},
  ColorFunctionScaling -> False, 
  ColorFunction -> (Blend[{Yellow, Brown}, indxs[{##}]] &)]


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

 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]

enter image description here

share|improve this answer
pts = RandomReal[1, {100, 3}];

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

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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