Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Piecewise ColorFunction
Replies: 2   Last Post: Mar 26, 2012 2:49 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Goyder Dr HGD

Posts: 59
Registered: 1/29/05
Piecewise ColorFunction
Posted: Mar 25, 2012 1:19 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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]




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.