MathGroup Archive 2012

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

Search the Archive

Piecewise ColorFunction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125652] Piecewise ColorFunction
  • From: Hugh Goyder <h.g.d.goyder at cranfield.ac.uk>
  • Date: Sun, 25 Mar 2012 00:17:46 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

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