# Visualization of a set of data with a shape $m \times n \times 3$ with the last dimension interpreted as a color scale

Actually, if the data is shaped as $$m \times n \times 2$$, functions like ListLinePlot just do the job. But now I want to add colors to the curves according to each 3rd data. But it has stuck me. Any ideas?

A simpler version of the question should be this: Suppose I have an $$n \times 3$$ shaped data (below is not code but just what shows the spirit, and generation of test data is not difficult to implement by, say, RandomReal or RandomInteger):

data = {{x1, y1, z1}, {x2, y2, z2}, ..., {xn, yn, zn}};


Using Graphics3D[Line[data]] or ListPointPlot3D[data] can visualize it. But sometimes one has to work in just 2D, then how to encode the information carried by zi on the 2D curve sampled out by {xi, yi}?

• It is unclear to me what type of data you want to visualize and what the result should be. Furthermore, I fail to see how ListLinePlot can handle $m \times n \times 2$ data strucutre. – Natas Jun 30 '20 at 10:37
• @Natas Thx for responding. Something like ListLinePlot[RandomReal[1, {3, 10, 2}]] answers your 2nd point. For the 1st one, please see the 4th example of Basic Examples on this page, except that there it is Plot that is in use for the case that the function expression of the curve is known. – Αλέξανδρος Ζεγγ Jun 30 '20 at 11:06

Clear[colorDataListLinePlot]
Options[colorDataListLinePlot] = {
"ColorScheme" -> "NeonColors"
}~Join~Options[ListLinePlot];
colorDataListLinePlot[datum_, opts : OptionsPattern[]] := Module[{
data = datum[[All, {1, 2}]],
colorfun =
Function[{x}, InterpolatingPolynomial[datum[[All, {1, 3}]], x]]
}, ListLinePlot[data,
ColorFunction ->
Function[{x, y},
ColorData[OptionValue["ColorScheme"]][colorfun[x]]],
FilterRules[{opts}, Options[ListLinePlot]]
]
]


The problem is that ColorFunction expects a continuous function and needs to be defined everywhere. I used InterpolatingPolynomial which does not give so nice results, but this might be because of the random nature of the data.

(*3 x 10 x 3 data structure with the "x"-component increasing*)
data = Table[{i, RandomReal[{-1, 1}], i}, {3}, {i, 10}];
Show@Table[
colorDataListLinePlot[datum, "ColorScheme" -> "Rainbow",
PlotRange -> {{1, 10}, {-1, 1}}], {datum, data}]


VertexColors:

data = Table[{x, Sin[x], Cos[x]}, {x, 0, 2 Pi}];
{x, y, z} = Transpose[data];

Graphics[{
Thick,
Line[Transpose[{x, y}], VertexColors -> Hue /@ z]
}]