Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

RE: how to plot 2 functions in different colors?

  • To: mathgroup at
  • Subject: [mg33605] RE: [mg33583] how to plot 2 functions in different colors?
  • From: David.Annetts at
  • Date: Wed, 3 Apr 2002 01:13:34 -0500 (EST)
  • Sender: owner-wri-mathgroup at

Hi Guojun,

> I can plot two functions in one diagram with 
> plot[{fa[x],fb[x]},{x,1,100}],
> but they are in same color and hard to seperated.  Is there 
> any way to make them in different colors?

Yes there is.

Just supply a list of plot styles, and plot functions are cycled with plot

For two functions, you can define:-
myStyle = {RGBColor[1, 0, 0], RGBColor[0, 1, 0], RGBColor[0, 0, 1]};

Plot[{x, 2x, 3x}, {x, 1, 100}, PlotStyle -> myStyle];

Or, with Graphics`Colors` loaded, you can use:-

Plot[{Sin[x], Cos[x]}, {x, -Pi, Pi}, PlotStyle -> {Red, Blue}, 
    FrameTicks -> {PiScale, Automatic, None, None}];

IMHO, it's usually easier to define a list of styles and use the list rather
than specify individual colours by their names.  One way of defining such a
list is:- 

maxNumberOfCurves = 12;
lst = Range[maxNumberOfCurves]/(maxNumberOfCurves + 1.)
myStyle2 = Hue[#] & /@ lst

There are other methods.


  Dr. David Annetts             EM Modelling Analyst
  Tel: (+612) 9490 5416         CSIRO DEM, North Ryde
  Fax: (+612) 9490 5467         David.Annetts at
                 Include "usual_disclaimers"

  • Prev by Date: QA Testing - Examples? Docs?
  • Next by Date: Re: information on Eigensystem
  • Previous by thread: Re: how to plot 2 functions in different colors?
  • Next by thread: minimization algorithms