ColorFunction
specifies that for ListLinePlot
it takes the $x,y$ data as inputs. I, however, would like to take the array index (or in general some external array of the same length) as the input for ColorFunction
so that, if we use a rainbow color scheme, the earlier points show up as purple while the last points show up as red. An application would be visualisation of the long time behaviour of some system when data is imported from an external source.
For example if we take
ListLinePlot[Table[E^-0.001 x {Cos[x], Sin[x]}, {x, 0, 100, 0.1}]]
then the outer lines should be purple ending up as red as the plot spirals in.
EDIT: I am now convinced the best thing you can do if you import a large amount of time ordered data into MMA is to immediately convert that data into an interpolation function and then use ParametricPlot
. Here is an example:
data = Table[{Sin[2 u], Cos[u]}, {u, 0, 100, 0.1}];
indexlist = Rescale[Range@Length@data] (*or your external list to control color*);
iF = Interpolation[MapThread[{#, #2} &, {indexlist, data}], InterpolationOrder -> 1];
ParametricPlot[iF[u], {u, 0, 1}, ColorFunction -> Function[{x, y, u}, ColorData["Rainbow"][u]]]
This answer is obviously based on @kglr's answer but the slight difference is he uses interpolation to return a color as a function of ${x,y}$ position while here interpolation is used to return ${x,y}$ as a function of time. In this way, if you have overlapping data as I do above, the later data is always plotted on the top.