Search code examples
plotwolfram-mathematicapoint

Colour ListPointPlot3D points by index in Mathematica


Is it possible to colour points based on list index value? E.g. suppose I have a set of coordinates

l1 := {{20.729858261394142, -11.014787072072988, 20.910738872021085}, {26.754953134772755, 12.795549555413617, 12.35084230079088}, {-26.240583655553486, 14.046344120397391, 4.267648394595125}, {-28.350142916856896, -15.381100510373342, 2.203525286738756}}

I then use this Mathematica command

ListPointPlot3D[l1, PlotStyle -> {Blue, PointSize[0.025]}]

I want to be able to specify the first point as red, the second a green, the third as blue, etc.

I'd rather not use Show[...] with multiple ListPointPlot3D commands...

I found this related question, but this colours based on (x, y, z) coordinate values.


Solution

  • another way:

    Graphics3D[{PointSize[0.05],
        MapIndexed[ { Blend[{Red, Green, Blue, Yellow},
            (1/Length@l1) First@#2], Point[#]} &, l1]}]
    

    In this form you can readily switch Point to Sphere which looks a bit nicer.