MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Piecewise ColorFunction


The first example below works to give a plot style with colours that vary with y-values. 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]



  • Prev by Date: Convert string to number
  • Next by Date: Re: Different answers in mathematica and my calculator.
  • Previous by thread: Convert string to number
  • Next by thread: Re: Piecewise ColorFunction