I'm helping my students with parametrization. I tried to change the color on the second rotation of the unit circle with this code:

 ParametricPlot[{Cos[2 t], Sin[2 t]}, {t, 0, tau}, PlotRange -> 1.2, 
  PlotStyle -> {If[t <= π, "Blue", "Red"]}],
 {{tau, 0.1}, 0, 2 π}]

But it remains blue after the first rotation. Can someone make a suggestion how to change the color?

  • 1
    $\begingroup$ "Blue" and "Red" should probably be replaced with just Blue and Red; colors are keywords in Mathematica mostly; see also GrayLevel, Hue, and RGBColor. Also, the parameter t is not defined generally outside of the first argument to the function; you should look at the ColorFunction option. $\endgroup$ – user16054 Jan 31 '17 at 19:28
  • $\begingroup$ @user16054 Yep, my mistake. Thanks for pointing it out. $\endgroup$ – David Jan 31 '17 at 19:42

You should be using ColorFunction, as PlotStyle does not do variable-dependent coloring:

Manipulate[ParametricPlot[{Cos[2 t], Sin[2 t]}, {t, -$MachineEpsilon, τ}, 
                          ColorFunction -> Function[{x, y, t}, If[t <= π, Blue, Red]], 
                          ColorFunctionScaling -> False, PlotRange -> 1.2],
           {{τ, 0.1}, 0, 2 π}]

Manipulate of colored circle

where I have also taken the liberty of offsetting the starting point in ParametricPlot[] to prevent errors when τ becomes 0, and using the colors as symbols instead of strings.

  • $\begingroup$ This provided some excellent help. May I ask one more question? How can I change the thickness on the second rotation? $\endgroup$ – David Jan 31 '17 at 19:56
  • $\begingroup$ Now that... is an excellent question. Let me think about it. $\endgroup$ – J. M. is away Jan 31 '17 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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