Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9281

Re: Piecewise ColorFunction

From Bob Hanlon <hanlonr357@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Piecewise ColorFunction
Date 2012-03-29 08:08 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jl159k$lf7$1@smc.vnet.net> (permalink)
References <201203280531.AAA08768@smc.vnet.net>

Show all headers | View raw


With the parentheses the function definition is the RHS of the rule.
Without the parentheses the whole rule becomes the function
definition. While obviously not what you intend, it is what you told
Mma to use.


Bob Hanlon

On Wed, Mar 28, 2012 at 1:31 AM, Alexei Boulbitch
<Alexei.Boulbitch@iee.lu> wrote:
> 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}}] &)]
>
>
> Dear community,
> In the above solution (given by David) the parentheses play an intriguing role. Indeed the solution above works, while the same solution but without the round parentheses flanking the Piecewise function, i.e. the following:
>
> Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick, ColorFunctionScaling -> False, ColorFunction -> Piecewise[{{Green, #2 < 0}, {Red, #2 >= 0}}] &]
>
> does not work. I wonder, why?
>
> Alexei BOULBITCH, Dr., habil.
> IEE S.A.
> ZAE Weiergewan,
> 11, rue Edmond Reuter,
> L-5326 Contern, LUXEMBOURG
>
> Office phone :  +352-2454-2566
> Office fax:       +352-2454-3566
> mobile phone:  +49 151 52 40 66 44
>
> e-mail: alexei.boulbitch@iee.lu
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Piecewise ColorFunction Bob Hanlon <hanlonr357@gmail.com> - 2012-03-29 08:08 +0000

csiph-web