# How do I interpolate a set of points with colour varying along the curve?

I have a table with 3 columns - x position, y-position and colour. I'd like to plot these points and join them with line segments, where the colour of the line segment is determined by 3rd variable. e.g.

T=Table[{n,n,n},{n,0,100}];


I can plot just the points like this

Graphics[{Hue[#3/Length[T]], Point[{#1, #2}]} & @@@ T, Frame -> True, AspectRatio -> 1]


How can I plot line segments instead?

Thanks!

-
It seems to be a duplicate but meanwhile try: {Hue[#1[[ 3]]/Length[T]], Line[{##}[[ ;; , ;; 2]]]} & @@@ Partition[T, 2, 1], –  Kuba Aug 26 '13 at 10:58
There are 100 points and 100 colors, which color you want to apply to line between n and n+1 point? the n.? –  Kuba Aug 26 '13 at 11:35
Possibly a duplicate of this question –  m_goldberg Aug 26 '13 at 15:47

T = Table[{n, n, n}, {n, 0, 10}];

Graphics[
GraphicsComplex[
T[[;; , ;; 2]],
{Thickness@.02, {Hue[T[[#[[ 1]], 3]]/len], Line@#} & /@ Partition[Range[len], 2, 1]
], Frame -> True, AspectRatio -> 1]


So that's another approach, but it will blur your colors:

len=Length @ T;

Graphics[
GraphicsComplex[
T[[ ;; , ;; 2]],
{Thickness@.02, Line[Range[len], VertexColors -> (Hue[#/len] & /@ T[[ ;; , 3]])]}
]
, Frame -> True, AspectRatio -> 1]


Edit:

GraphicsComplex can be useful but for simple cases like here or the one I've faced today it is not a must:

T = Table[{n, n, n}, {n, 0, 10}];
len = Length@T;

Graphics[{Thickness@.02,
Line[T[[ All, {1, 2}]],
VertexColors -> (Hue[#/len] & /@ T[[;; , 3]])]}
]

-
That's perfect thanks! I prefer the blurred one but I didn't know if it was possible. I don't have enough reputation to upvote the answer... sorry –  octopus Aug 26 '13 at 12:10

If I understood you correctly, - there is a simpler way:

data = Table[{x, Sinc[x]}, {x, 0, 10, .5}];

ListPlot[data,
ColorFunction -> Hue,
Joined -> True,
PlotStyle -> Thickness[.03],
Mesh -> All,
MeshStyle -> Directive[PointSize[.05], Opacity[.2]]]


-
as I understand, he'd explicilty give the color as 3rd argument of the individual points –  Pinguin Dirk Aug 26 '13 at 11:20
@PinguinDirk Yeah I thought it is a possibility. Still you never know. Additionally this is good to know and ColorFunction can be custom in case he just need to specify a simple data-dependent coloring scheme. –  Vitaliy Kaurov Aug 26 '13 at 11:46
perfectly understand- it is what I'd suggest to use too (I am too lazy to build up with primitives when there are built-in functions one could use) –  Pinguin Dirk Aug 26 '13 at 11:48
Many thanks for your answer. In reality, I need to give the colour as an extra argument. (I have a 2D trajectory and want to use the colour to track the time taken to reach each point) –  octopus Aug 26 '13 at 12:12