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: [mg87441] Re: Just primitive ColorFunction
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Thu, 10 Apr 2008 02:16:35 -0400 (EDT)
  • Organization: University of Bergen
  • References: <ftfej7$bu7$1@smc.vnet.net> <ftfk8g$fab$1@smc.vnet.net> <fti3t8$oem$1@smc.vnet.net>

ucervan at gmail.com wrote:
> You could also use:
> 
> Plot[Sin[x], {x, 0, 4 Pi}, AxesOrigin -> {0, 0}, Axes -> {True, True},
>   PlotStyle -> Thick,
>  ColorFunction -> (If[Sin[#] >= 0, RGBColor[1, 0, 0],
>      RGBColor[0, 0, 1]] &), Filling -> Axis, ImageSize -> {380, 280},
>  ColorFunctionScaling -> False, FillingStyle -> Automatic]
> 
> Note that the output will be much bigger since VertexColors are
> generated for each vertex. Also, segments crossing the x axis will
> have end vertices of different colors, so some color bleeding will
> occur.
> 

What is a good way to avoid this "colour bleeding" problem?  If we want 
to colour only the lines (but use no fillings), then this looks very ugly:

Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick,
  ColorFunction -> (If[Sin[#] >= 0, RGBColor[1, 0, 0],
      RGBColor[0, 0, 1]] &), ColorFunctionScaling -> False]

One solution I found is the following:

Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick,
  ColorFunction -> (If[Sin[#] >= 0, RGBColor[1, 0, 0],
      RGBColor[0, 0, 1]] &), ColorFunctionScaling -> False,
  Exclusions -> {Pi, 2 Pi, 3 Pi}]

But Exclusions was not designed for this.  I am not confortable using it 
because I am afraid that it might skip a section of the curve as with 
Exclusions -> {Sin[x] == 0}.

1.  Is there a more appropriate way to force Plot to calculate the 
function value at certain points?

2.  Is there a way to avoid having to find the zeros of the function 
manually?  (More generally: avoid having to calculate the points where 
the colouring changes abruptly.)

Szabolcs Horvát


  • Prev by Date: Re: Trace'ing Gradient in FindMinimum
  • Next by Date: Re: Trace'ing Gradient in FindMinimum
  • Previous by thread: Re: Just primitive ColorFunction
  • Next by thread: Re: Just primitive ColorFunction