MathGroup Archive 2012

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

Search the Archive

Re: Piecewise ColorFunction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125653] Re: Piecewise ColorFunction
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Mon, 26 Mar 2012 01:45:15 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201203250517.AAA12261@smc.vnet.net>

>From the documentation: "With the usual default setting
ColorFunctionScaling -> True, all arguments supplied to func are
scaled to lie in the range 0 to 1."

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

Plot[Sin[x], {x, 0, 4 Pi},
 PlotStyle -> Thick,
 ColorFunction -> Function[{x, y}, f[y - 1/2]]]

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

ClearAll[f];
f = Piecewise[{{Green, #2 < 0}, {Red, #2 >= 0}}] &;

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


Bob Hanlon


On Sun, Mar 25, 2012 at 1:17 AM, Hugh Goyder
<h.g.d.goyder at cranfield.ac.uk> 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]
>



  • Prev by Date: Re: Piecewise ColorFunction
  • Next by Date: Re: Exporting a formula to Excel via copypaste
  • Previous by thread: Piecewise ColorFunction
  • Next by thread: Re: Piecewise ColorFunction