Re: creating functions with variable number of options
- To: mathgroup at smc.vnet.net
- Subject: [mg33116] Re: [mg33109] creating functions with variable number of options
- From: BobHanlon at aol.com
- Date: Sun, 3 Mar 2002 17:15:19 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 3/3/02 7:23:10 AM, Okke at NOSPAMtref.nl writes:
>I want to create a function with an option to set the plot color.
>After looking at the examples I was cabable of making a function
>in which I could add an option, but I couldnt merge the additional
>option with the used option inside the function.
>
>could somebody please help me and tell me how I can make the function
>and function call below work?
>
>tia,
>
>
>xPlot[function_, range_] :=
> Plot[function, range,PlotStyle -> {Thickness[0.02]}]
>
>xPlot[Sin[n], {n, 0, 2 Pi}, PlotStyle -> {RGBColor[0, 1, 0]}]
>
Needs["Utilities`FilterOptions`"];
Defining the default options for xPlot
Options
[xPlot] = {PlotStyle->{Thickness[0.02]}};
xPlot[func_, rng_, opts___Rule] :=
With[{optPlot = FilterOptions[Plot, opts],
pltStyl = PlotStyle /. {opts} /. Options[xPlot]},
Plot[func, rng, PlotStyle->pltStyl, optPlot]];
Using default PlotStyle
xPlot[Sin[n],{n,0,2 Pi}];
Overriding the default
xPlot[Sin[n],{n,0,2 Pi},PlotStyle->{RGBColor[0,1,0]}];
Adding to the default
xPlot[Sin[n],{n,0,2 Pi},
PlotStyle->Join[PlotStyle/.Options[xPlot], {RGBColor[0,1,0]}]];
Bob Hanlon
Chantilly, VA USA