MathGroup Archive 2009

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

Search the Archive

Re: Changing Line Color in Plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96093] Re: Changing Line Color in Plot
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Thu, 5 Feb 2009 04:36:46 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <gmbr6k$iib$1@smc.vnet.net>

In article <gmbr6k$iib$1 at smc.vnet.net>,
 "Yerex, Robert" <robert.yerex at kronos.com> wrote:

> I am trying to change the color of a line in a simple Plot of a function
> but want the color to be based on a value outside of that function. Any
> Idea?

Not sure whether this is exactly what you are looking for but one can 
control the appearance of a plot with options such as *ColorFunction* or 
*PlotStyle*, to name a few.

Now the values of these options can be passed directly into the plot 
command, as in

  Plot[Sin[x], {x, 0, 2 Pi}, 
   ColorFunction -> Function[{x, y}, If[y > 0, Orange, Green]], 
   ColorFunctionScaling -> False, PlotStyle -> Directive[Thick]]

or can be passed via symbols that are defined outside the plot command 
and can themselves depend on some other global values. For instance,

  myStyle = Directive[thicknessOfTheLine];
  myFun = Function[{x, y}, If[y > 0, Orange, Green]];
  thicknessOfTheLine = Thick;

  Plot[Sin[x], {x, 0, 2 Pi}, ColorFunction -> myFun, 
   ColorFunctionScaling -> False, PlotStyle -> myStyle]

(Note that, in some cases, you may have to use := *SetDelayed* rather 
than = *Set* .)

HTH,
--Jean-Marc


  • Prev by Date: Re: simplifying a resulted derivative expression
  • Next by Date: Changing the height of baseline in Histograms
  • Previous by thread: Re: Changing Line Color in Plot
  • Next by thread: Re: Changing Line Color in Plot