# Change plot style as function of parameter in ParametricPlot

The Manipulate below produces a path traversing the upper unit semicircle, going from {1,0} at time 0 to {-1,0} at time 1/2, then traversing the same upper semicircle, but in the reverse direction, going back from {-1,0} at time 1/2 to {1,0} at time 1.

However, one cannot "see" the reverse half of the path, since it lies on top of the same semicircle, but traversed in the reverse direction, of the forward half.

Is it possible to use a PlotStyle, or other directive, to change the style of the curve at time 1/2 so that, for example, the plot from then onward is thicker and a different color?

f[t_ /; 0 <= t <= 1/2] := ReIm[Exp[2 \[Pi] I t]]
f[t_ /; 1/2 < t <= 1] := ReIm[Exp[2 \[Pi] I (1 - t)]]

Manipulate[
ParametricPlot[f[t], {t, 0, v},
PlotRange -> {{-1, 1}, {-1, 1}}], {{v, 0.01}, 0.01, 1}]


(I do realize that there's a way to fake the result I want, namely, by changing the function f on the half-interval {1/2, 1} so as to have a slightly greater radius than 1. But I would much prefer to leave the radius unchanged and "merely" change the style of the curve's thickness and/or color on that half-interval.)

• The easy solution would be to rename the second definition g and then plot {f[t], g[t]}. – C. E. Sep 12 '20 at 17:45

Clear["Global*"]

f[t_ /; 0 <= t <= 1/2] := ReIm[Exp[2 \[Pi] I t]]
f[t_ /; 1/2 < t <= 1] := ReIm[Exp[2 \[Pi] I (1 - t)]]


You could use ColorFunction

EDIT:

Manipulate[
ParametricPlot[f[t], {t, 0, v},
PlotRange -> {{-1, 1}, {-1, 1}},
ColorFunction -> (If[#3 < 1/2, Blue, Red] &),
ColorFunctionScaling -> False],
{{v, 0.01}, 0.01, 1, 0.01, Appearance -> "Labeled"}]

• I want constant styling for 0 <= t <= 1/2 and then different constant styling for 1/2 < t <= 1, but in each case, only for the arc currently being traversed. The points in your Manipulate become blue well before t reaches 1/2, so that one cannot see the retracing backwards until around t = 0.6. – murray Sep 12 '20 at 19:41
• Exactly what I was after. Thank you! – murray Sep 12 '20 at 21:23
• This method, and those in other answers, can be enhanced by including something like: Epilog -> {PointSize[Large], Point[f[v]]} so as to show the moving point tracing out the path. – murray Sep 13 '20 at 16:05

The plot of a single function without singularities will result in a single Line object, which can only a single thickness. To get two thicknesses, you would need to draw two lines. This may or may not be acceptable, since it doesn't look like a single function.

Either

Manipulate[
ParametricPlot[{
Style[ConditionalExpression[f[t], t <= 1/2], AbsoluteThickness[1], Blue],
Style[ConditionalExpression[f[t], t >= 1/2], AbsoluteThickness[3], Red]},
{t, 0, v},
PlotRange -> {{-1, 1}, {-1, 1}},
{{v, 0.01}, 0.01, 1, 0.01, Appearance -> "Labeled"}]


or

Manipulate[
ParametricPlot[{
ConditionalExpression[f[t], t <= 1/2],
ConditionalExpression[f[t], t >= 1/2]},
{t, 0, v},
PlotRange -> {{-1, 1}, {-1, 1}},
PlotStyle -> {
Directive[AbsoluteThickness[1], Blue],
Directive[AbsoluteThickness[3], Red]},
{{v, 0.01}, 0.01, 1, 0.01, Appearance -> "Labeled"}]

• An equally good solution to Bob Hanlon's (mathematica.stackexchange.com/a/230025/148), having only the slight "defect" that it uses the two ConditionalExpression clauses (which is clever, though!). – murray Sep 12 '20 at 21:29
• @murray I agree about the two expressions, but I think it's the cleanest way, if not the only way, to get two thicknesses. – Michael E2 Sep 12 '20 at 21:40
• @murray Here's another way but I think it's too tricky: Module[{i = 1}, ParametricPlot[ f[t], {t, 0, v}, Exclusions -> t == 1/2, ExclusionsStyle -> Red, PerformanceGoal -> "Quality", PlotRange -> {{-1, 1}, {-1, 1}}, PlotRangePadding -> Scaled[0.01]] /. l_Line :> {{Directive[AbsoluteThickness[1], Blue], Directive[AbsoluteThickness[3], Red], Directive[AbsoluteThickness[3], Red]}[[i++]], l} ] – Michael E2 Sep 12 '20 at 21:49

You can also use MeshFunctions, Mesh and MeshShading options as follows:

Manipulate[ParametricPlot[f[t], {t, 0, v},
MeshFunctions -> {#3 &},
Mesh -> {{1/2}},
MeshStyle -> None,
Directive[CapForm["Butt"], AbsoluteThickness[4],
Dashing[{Large, Medium}], Red]},
PlotRange -> {{-1, 1}, {-1, 1}} 1.1],
{{v, 0.01}, 0.01, 1}]


Use

MeshShading -> {Directive[AbsoluteThickness[1], Blue],
Directive[AbsoluteThickness[7], Dashing[{Large, Medium}], Opacity[.5, Red]]}


to get

f[t_ /; 0 <= t <= 1/2] := ReIm[Exp[2 π I t]]
f[t_ /; 1/2 < t <= 1] := ReIm[Exp[2 π I (1 - t)]]

Manipulate[
ParametricPlot[f[t], {t, 0, v}, PlotRange -> {{-1, 1}, {-1, 1}},
ColorFunction -> Function[{t}, If[t > 1/4, Blue, Black]],
ColorFunctionScaling -> False], {{v, 0.01}, 0.01, 1}]


Manipulate[
ParametricPlot[f[t], {t, 0, v}, PlotRange -> {{-1, 1}, {-1, 1}},
PlotStyle -> If[v > 1/4, {Blue, Bold}, {Black, Dashed}]], {{v,
0.01}, 0.01, 1}]


• That does not do what I need: at time 1/4 (which should be 1/2, not 1/4), it suddenly changes the entire semicircular arc already traced to the new style! After time 1/2, I only want to see the new style applied to the portion of the arc traced from time 1/2 up to time v`. – murray Sep 12 '20 at 19:07