Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9226 > unrolled thread
| Started by | Hugh Goyder <h.g.d.goyder@cranfield.ac.uk> |
|---|---|
| First post | 2012-03-25 05:19 +0000 |
| Last post | 2012-03-26 06:47 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Piecewise ColorFunction Hugh Goyder <h.g.d.goyder@cranfield.ac.uk> - 2012-03-25 05:19 +0000
Re: Piecewise ColorFunction Helen Read <readhpr@gmail.com> - 2012-03-26 06:49 +0000
Re: Piecewise ColorFunction David Skulsky <edskulsky@gmail.com> - 2012-03-26 06:47 +0000
| From | Hugh Goyder <h.g.d.goyder@cranfield.ac.uk> |
|---|---|
| Date | 2012-03-25 05:19 +0000 |
| Subject | Piecewise ColorFunction |
| Message-ID | <jkm9sp$bvr$1@smc.vnet.net> |
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]
[toc] | [next] | [standalone]
| From | Helen Read <readhpr@gmail.com> |
|---|---|
| Date | 2012-03-26 06:49 +0000 |
| Message-ID | <jkp3i1$kvt$1@smc.vnet.net> |
| In reply to | #9226 |
- 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
[toc] | [prev] | [next] | [standalone]
| From | David Skulsky <edskulsky@gmail.com> |
|---|---|
| Date | 2012-03-26 06:47 +0000 |
| Message-ID | <jkp3e6$kuq$1@smc.vnet.net> |
| In reply to | #9226 |
On Sunday, March 25, 2012 12:19:21 AM UTC-5, 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]
I think this does what you want:
Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick, ColorFunctionScaling -> False, ColorFunction -> (Piecewise[{{Green, #2 < 0}, {Red, #2 >= 0}}] &)]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web