0
$\begingroup$

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

enter image description here

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?

$\endgroup$
6
  • 1
    $\begingroup$ It will be easier with Graphics + Line + some color function. $\endgroup$
    – Kuba
    Commented Nov 22, 2014 at 19:15
  • $\begingroup$ I tried that, but I could not get the ColorFunction to work. Could you provide an example, please? $\endgroup$
    – Erika H
    Commented Nov 22, 2014 at 19:16
  • $\begingroup$ I mean color function like Hue or custom Blend etc. $\endgroup$
    – Kuba
    Commented Nov 22, 2014 at 19:18
  • $\begingroup$ 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. $\endgroup$
    – Erika H
    Commented Nov 22, 2014 at 19:28
  • $\begingroup$ ArcTan runs from -π to π. Check out Rescale. E.g. Hue[Rescale[ArcTan[x,y],{-Pi,Pi}]] or something like that. $\endgroup$
    – Michael E2
    Commented Nov 22, 2014 at 20:47

1 Answer 1

2
$\begingroup$

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]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you! I had a feeling it would be easier with PlotStyle. $\endgroup$
    – Erika H
    Commented Nov 22, 2014 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.