MathGroup Archive 2001

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

Search the Archive

RE: Q: Print in different colors

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27945] RE: [mg27930] Q: Print in different colors
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 24 Mar 2001 15:15:48 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Robert,

You could do it this way:

c = {RGBColor[1, 0, 0], RGBColor[0, 1, 0], RGBColor[0, 0, 1]};
SetOptions[Plot, PlotStyle -> c];
Plot[{Sin[1*x], Sin[2*x], Sin[3*x]}, {x, 0, Pi}]
k = Table[StyleForm[i, FontColor -> c[[i]]], {i, 3}];
Print["k=", k];

You could also identify the curves with color right in the PlotLabel. When
using colors, I always find it handy to use the Graphics`Colors` standard
package. Then you could make a somewhat nicer plot this way.

Needs["Graphics`Colors`"]

c = {Red, SeaGreen, Blue};
f[i_][x_] := Sin[i*x]
Plot[Evaluate[Table[f[i][x], {i, 3}]], {x, 0, Pi}, PlotStyle -> c,
   Frame -> True, FrameLabel -> {x, y}, ImageSize -> 500,
   Background -> Linen, PlotLabel -> SequenceForm @@
     Table[StyleForm[f[i][x], FontColor -> c[[i]]]If[i == 3, "", ", "],
      {i, 3}]];

A third suggestion is to use the Legend package.

Needs["Graphics`Legend`"]

c = {Red, SeaGreen, Blue};
f[i_][x_] := Sin[i*x]
Plot[Evaluate[Table[f[i][x], {i, 3}]], {x, 0, Pi}, PlotStyle -> c,
   Frame -> True, FrameLabel -> {x, y}, ImageSize -> 500,
   Background -> Linen, PlotLabel -> "Various Sin Functions",
   PlotLegend -> Table[f[i][x], {i,3}], LegendSize -> 0.5];

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



> From: Robert Schuerhuber [mailto:robert.schuerhuber at gmx.at]
To: mathgroup at smc.vnet.net
>
> hello again!
> some time again i managed it with the help of this group to cycle the
> colors of a plot automatically, when i plot a list. i'm printing the
> information about the curves below the plot, and it would be very
> helpful if this information would be in the same color as the plot,
> because sometimes its very hard to say which curve belongs to which
> paramter. i'll give a simple example:
>
> c = {RGBColor[1, 0, 0], RGBColor[0, 1, 0], RGBColor[0,0,1]};
> SetOptions[Plot, PlotStyle -> c];
> Plot[{Sin[1 x],Sin[3 x],Sin[3 x]},{x,0,Pi}]
> k={1,2,3};
> Print["k=",k];
>
> so the three curves are plotted in red, green and blue, respectively,
> and i'd like the "k"-list printed in the next line also to appear in the
> same color, therefore "1" printed in red, "2" in green and "3" in blue.
> is there a way to do this, it would really save me a lot of time!
>
> regards, robert
>
>
>
>
>



  • Prev by Date: errors with Compile?
  • Next by Date: Re: DSolve bug in Mathematica version 4.1?,
  • Previous by thread: Re: Q: Print in different colors
  • Next by thread: DSolve bug in Mathematica version 4.1?,