Color a 3D line plot of list of lists

Assume a list of lists of length n of the kind:

t = {{x1, y1, z1, p1},{x2, y2, z2, p2},...,{xn, yn, zn, pn}}.

1. I'd like to make a ListLinePlot3D of the list given by t[[All,{1,2,3}]]. I'm working with Mathematica 11.0, so the function ListLinePlot3D is not available. I've failed to adapt my problem to what is recommended here. Maybe the function ParametricPlot3D may do the job as well, but I can't figure it out.
2. The resulting line should be colored using the values p1, p2,...,pn as arguments for the ColorFunction. These values range from 0 to 0.86.

• Please include the Mathematica code that you have tried out so far. Also to make this question concrete, include t (list of points).
– Syed
Commented Nov 23, 2021 at 6:22

SeedRandom[123];

t = RandomReal[1, {10, 4}];

minmax = MinMax[t[[All, 4]]];

color[x_] := ColorData["Rainbow"][Rescale[x, minmax]]

Graphics3D[{AbsoluteThickness[2],
Line[{Most@#[[1]], Most@#[[2]]},
VertexColors ->
{color@Last@#[[1]],
color@Last@#[[2]]}] & /@
Partition[t, 2, 1],
AbsolutePointSize[4],
{color[Last@#], Point[Most@#]} & /@ t},
Axes -> True]


SeedRandom[123]
xyzp = RandomReal[1, {10, 4}];


Graphics3D

Two additional variations using Graphics3D + VertexColors:

plt1 = Graphics3D[{Thick, PointSize[Large],
#[xyzp[[All, ;; 3]], VertexColors ->
(ColorData["Rainbow"] /@ Rescale[xyzp[[All, 4]]])]& /@ {Line, Point}},
ImageSize -> Medium];

plt2 = Graphics3D[GraphicsComplex[xyzp[[All, ;; 3]],
{Thick, PointSize[Large],
#[Range @ Length @ xyzp, VertexColors -> Automatic]& /@ {Line, Point}},
VertexColors -> (ColorData["Rainbow"] /@ Rescale[xyzp[[All, -1]]])],
ImageSize -> Medium];

Row[{plt1, plt2}, Spacer[10]]


ParametricPlot3D

Use BSplineFunction to get spline interpolations of the first three coordinates to define a custom ColorFunction using spline interpolation of the last coordinates, and use the options MeshFunctions + Mesh + Method to add styled points:

bSF = BSplineFunction[xyzp[[All, ;; 3]], SplineDegree -> 1];

cF = ColorData["Rainbow"][BSplineFunction[Rescale@xyzp[[All, 4]], SplineDegree -> 1]@#] &

ParametricPlot3D[bSF[t], {t, 0, 1},
ColorFunction -> (cF@ # 4 &),
MeshFunctions -> {#4 &},
Mesh -> {{#, Directive[PointSize[Large], cF@#]} & /@ Subdivide[Length@ xyzp -1]},
Method -> {"BoundaryOffset" -> False},
ImageSize -> Medium, Ticks -> None, PlotRange -> All]


ListLinePlot3D

For those with version 12.3+, a way to use ListLinePlot3D with a custom ColorFunction:

iF = Interpolation[Thread[{xyzp[[All, ;; 3]], Rescale[xyzp[[All, 4]]]}],
InterpolationOrder -> 1,
"ExtrapolationHandler" -> {Automatic, "WarningMessage" -> False}];

cFLLP = ColorData["Rainbow"]@iF[#, #2, #3] &;

ListLinePlot3D[xyzp[[All, ;; 3]],
ColorFunction -> cFLLP,
PlotStyle -> Thick,
ImageSize -> Large,
Ticks -> None, BoxRatios -> 1,
PlotMarkers -> {Automatic, Large}] /.
Point[x_, _] :> Point[x, VertexColors -> (cFLLP @@ x)]


If you do not have ListLinePlot3D, you can still use Line together with Graphics:

dat = RandomReal[{-1, 1}, {5, 3}];
Graphics3D[{Line[dat]}]