Re: Piecewise ColorFunction
- To: mathgroup at smc.vnet.net
- Subject: [mg125656] Re: Piecewise ColorFunction
- From: David Skulsky <edskulsky at gmail.com>
- Date: Mon, 26 Mar 2012 01:46:18 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jkm9sp$bvr$1@smc.vnet.net>
On Sunday, March 25, 2012 12:19:21 AM UTC-5, Hugh Goyder wrote: > 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] I think this does what you want: Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick, ColorFunctionScaling -> False, ColorFunction -> (Piecewise[{{Green, #2 < 0}, {Red, #2 >= 0}}] &)]