Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: Piecewise ColorFunction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125660] Re: Piecewise ColorFunction
  • From: Helen Read <readhpr at gmail.com>
  • Date: Mon, 26 Mar 2012 01:47:41 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jkm9sp$bvr$1@smc.vnet.net>

- Try If or Which instead of Piecewise
- The function is f[x,y], not f
- You still need to tell to use Function[{x,y},  ] to associate with the 
{x,y} coordinates in the plot

Like so:

Clear[f];
f[x_, y_] := If[y < 0, Green, Red];

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




Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick,
  ColorFunction ->
   Function[{x, y},
    Which[Abs[y] < 1/2, Red, y >= 1/2, Blue, y <= -1/2, Green]],
  ColorFunctionScaling -> False]


Helen Read
University of Vermont



On 3/25/2012 1:19 AM, 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]
>


-- 
HPR



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