TransWikia.com

ColorFunction issues. Using different colors for different values of x

Mathematica Asked by SeBa on November 1, 2020

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]
   ]
 ]

enter image description here

One Answer

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
 ]

Mathematica graphics

Answered by C. E. on November 1, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP