# ColorFunction that depends on angle of line

I have a ListLinePlot, and I want the ColorFunction to vary as the angle, so that the color of the whole line depends on its angle from the x-axis. Here is a MWE of what I am doing:

test = Table[{i, 5 i}, {i, 1, 10}];
ListLinePlot[
Table[{{-test[[i, 1]] Cos[test[[i, 2]] Degree], -test[[i, 1]] Sin[
test[[i, 2]] Degree]}, {test[[i, 1]] Cos[test[[i, 2]] Degree], test[[i, 1]] Sin[test[[i, 2]] Degree]}}, {i, 1, 10}],
ColorFunction -> "ThermometerColors", ColorFunctionScaling -> True]


As expected, this produces How do I construct the ColorFunction so that the "minimum" and "maximum" color correspond to the angle of inclination, i.e. so that the minimum angle (5 Deg in this case) gives a blue line, and the maximum angle gives a red line?

• It will be easier with Graphics + Line + some color function. – Kuba Nov 22 '14 at 19:15
• I tried that, but I could not get the ColorFunction to work. Could you provide an example, please? – Erika H Nov 22 '14 at 19:16
• I mean color function like Hue or custom Blend etc. – Kuba Nov 22 '14 at 19:18
• Right, I see. I tried Hue[ArcTan[x,y]], and it seems to color it like I want, except only the negative half of the line is colored. – Erika H Nov 22 '14 at 19:28
• ArcTan runs from -π to π. Check out Rescale. E.g. Hue[Rescale[ArcTan[x,y],{-Pi,Pi}]] or something like that. – Michael E2 Nov 22 '14 at 20:47

if you want specifically "ThermometerColors" then try this:

color = ColorData["ThermometerColors"][#] & /@ Range[0, 1, .1];
ListLinePlot[
Table[{{-test[[i, 1]] Cos[test[[i, 2]] Degree], -test[[i, 1]] Sin[
test[[i, 2]] Degree]}, {test[[i, 1]] Cos[test[[i, 2]] Degree],
test[[i, 1]] Sin[test[[i, 2]] Degree]}}, {i, 1, 10}],
PlotStyle -> color] • Thank you! I had a feeling it would be easier with PlotStyle. – Erika H Nov 22 '14 at 22:16