6
$\begingroup$

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!

$\endgroup$

5 Answers 5

4
$\begingroup$

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:

Mathematica graphics

$\endgroup$
3
$\begingroup$

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.

$\endgroup$
3
$\begingroup$

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[{##}]] &)]

3DPlot

$\endgroup$
1
  • $\begingroup$ Fair enough, removed that remark. And +1 :) $\endgroup$
    – Szabolcs
    Jul 27, 2014 at 3:43
1
$\begingroup$
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]

enter image description here

$\endgroup$
0
$\begingroup$
SeedRandom[1];
pts = RandomReal[1, {100, 3}];

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

enter image description here

$\endgroup$

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.