
Piecewise ColorFunction
Posted:
Mar 25, 2012 1:19 AM


The first example below works to give a plot style with colours that vary with yvalues. I then try to define a Piecewise function for the colour and this does not work. Am I doing something wrong? Thanks for any assistance.
Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle > Thick, ColorFunction > Function[{x, y}, ColorData["NeonColors"][y]]]
ClearAll[f]; f[x_, y_] := Piecewise[{{Green, y < 0}, {Red, y >= 0}}]
Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle > Thick, ColorFunction > f]

