# ColorFunction issues. Using different colors for different values of x

I am attempting to generate a plot for which the color changes for selected values of x as determined by a function. Below, is my best, unsuccessful attempt. The specific problem with this is that it worked only once for x = 3Pi/4 but not for x = Pi/4. I am stumped, please help!

Plot[
{Cos[x], Sin[x]}, {x, 0, Pi},
ColorFunction -> Function[
x,
If[Abs[Cos[x]] > Abs[Sin[x]], Red, Blue]
]
]


• Plot[{Cos[x], Sin[x]}, {x, 0, Pi}, ColorFunction -> Function[x, If[Abs[Cos[x]] > Abs[Sin[x]], Red, Blue]], ColorFunctionScaling -> False] Sep 27, 2020 at 7:44
• Plot[{Sin[x], Cos[x]}, {x, 0, Pi}, MeshFunctions -> Function[{x, y}, Abs[Cos[x]] - Abs[Sin[x]]], MeshShading -> {Blue, Red}, Mesh -> {{0}}] is another way. Sep 27, 2020 at 8:19

You need to set ColorFunctionScaling to False, otherwise the x coordinate will be rescaled to lie between 0 and 1 before it is passed to the color function.

Plot[
{Cos[x], Sin[x]}, {x, 0, Pi},
ColorFunction -> Function[
{x, y},
If[
Abs[Cos[x]] > Abs[Sin[x]],
Red,
Blue
]
],
ColorFunctionScaling -> False
]