Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Just primitive ColorFunction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87404] Re: Just primitive ColorFunction
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Thu, 10 Apr 2008 02:09:23 -0400 (EDT)
  • References: <ftfej7$bu7$1@smc.vnet.net>

=8Aer=FDch Jakub wrote:
> I think, that it must be something very simple, but I cannot find the
> solution....
>
> I need to fill the Plot so, that area above the axis will be red and ar=
ea
> below the axis will be blue. I tried it in a such way:
>
> Plot[Sin[x], {x, 0, 4 Pi} ,
>  AxesOrigin -> {0, 0},
>  Axes -> {True, True},
>  PlotStyle -> Thick,
>  ColorFunction ->
>   If[Sin[x] >= 0, RGBColor[1, 0, 0], RGBColor[0, 0, 1]],
>  Filling -> Axis,
>  ImageSize -> {380, 280}]
>
> But Mathematica says, that If is not a valid Color.
>
> If I try it with Function (according to examples in ColorFunction help)=
,
>
> ColorFunction ->
>  Function[x, If[Sin[x] >= 0, RGBColor[1, 0, 0], RGBColor[0, 0, 1]]],
>
> it is working, but the color of Filling is red allover the range.
>
> Thanks for any hint, how to achieve the +Red/-Blue filling.
>
> Jakub
>
>
Although others have given you a simpler solution to your particular
problem, I thought it was worthwhile to fix your approach because it is
obviously more general:

Plot[Sin[x], {x, 0, 4 Pi}, AxesOrigin -> {0, 0}, Axes -> {True, True},
   PlotStyle -> Thick,
  ColorFunction ->
   Function[{x, y}, If[y >= 0, RGBColor[1, 0, 0], RGBColor[0, 0, 1]]],
  Filling -> Axis, ImageSize -> {380, 280},
  ColorFunctionScaling -> False]

Without the option  ColorFunctionScaling -> False, the {x,y} values are
scaled 0-1 across the plot, regardless of the actual coordinates (seems
a strange default to me!).

David Bailey
http://www.dbaileyconsultancy.co.uk




  • Prev by Date: JLink Problem, Fixed More or Less
  • Next by Date: Re: Pattern problem: How to count from a long list of numbers
  • Previous by thread: Re: Just primitive ColorFunction
  • Next by thread: Re: Just primitive ColorFunction