Re: plot in different colors
- To: mathgroup at smc.vnet.net
- Subject: [mg27704] Re: plot in different colors
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Mon, 12 Mar 2001 02:09:47 -0500 (EST)
- References: <98cfmm$fhl@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Robert,
Two ways:
1) We can set the default option PlotStyle for all uses of Plot.
SetOptions[Plot, PlotStyle->Table[Hue[i],{i,0, .7, .7/2}]];
Plot[{x,x^2, Sin[x]},{x,0,1}];
The styles will cycle when plotting more expressions.
Plot[{x,x^2, Sin[x],Cos[x]},{x,0,1}];
And the first few will be used for fewer expressions.
Plot[{x,x^2},{x,0,1}];
If we know that you are never going to use more than k functions we can use
SetOptions[Plot, PlotStyle->Table[Hue[i],{i,0, .7, .7/(k-1)}]];
2) Here is another way, it will allow all lines to be styled differently.
We could use Dashing and Thickness as well as color with both these
rechniques
ClearAll["`*"]
Options[myPlot]= Options[Plot];
Options[myPlot]= SetOptions[myPlot, PlotStyle->({}&)];
SetOptions[myPlot, PlotStyle-> (Hue[.7#]&)];
myPlot[exprs_,rng_,opts___?OptionQ]:=
Module[{sf,ln,stl},
sf = PlotStyle/.Flatten[{opts}]/.Options[myPlot];
ln = Length[Flatten[{exprs}]];
stl = Table[sf[k/(ln-1)],{k,0, ln -1}];
Plot[exprs, rng, PlotStyle-> stl, opts]
]
myPlot[{x,x^2, Sin[x]},{x,0,1}];
myPlot[{x,x^2, Sin[x], Cos[x],Tan[x]},{x,0,1}];
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Robert" <robert.schuerhuber at gmx.at> wrote in message
news:98cfmm$fhl at smc.vnet.net...
> hi!
> if i plot a list of functons, how can i command mathematica to plot each
> function in a different color? i know i can use rgbcolor to change the
> color of the plot, but it is not practical to enter a list of
> rgbcolor[r,g,b] values at each plot. is there an (easy) solution to do
> this more or less automatically?
> regards, robert
>
>