Re: Piecewise ColorFunction

• To: mathgroup at smc.vnet.net
• Subject: [mg125657] Re: Piecewise ColorFunction
• From: "djmpark" <djmpark at comcast.net>
• Date: Mon, 26 Mar 2012 01:46:39 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <22324383.161322.1332653209094.JavaMail.root@m06>

```Two problems: the symbol f is not a Function, and ColorFunctionScaling->
False is needed.

ClearAll[f];
f[x_, y_] := Piecewise[{{Green, y < 0}, {Red, y >= 0}}]

Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick,
ColorFunctionScaling -> False,
ColorFunction -> (f[#1, #2] &)]

Or define something that is a Function.

ClearAll[g];
g := Function[{x, y}, Piecewise[{{Green, y < 0}, {Red, y >= 0}}]]

Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick,
ColorFunctionScaling -> False,
ColorFunction -> g
]

Otherwise, your use of Piecewise is a neat way to color!

David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/index.html

From: Hugh Goyder [mailto:h.g.d.goyder at cranfield.ac.uk]

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: Re: Piecewise ColorFunction
• Next by Date: Re: Piecewise ColorFunction
• Previous by thread: Re: Piecewise ColorFunction
• Next by thread: Re: Piecewise ColorFunction