Re: passing options to a new graphics function
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg565] Re: [mg549] passing options to a new graphics function
- From: bob Hanlon <hanlon at pafosu2.hq.af.mil>
- Date: Sat, 18 Mar 1995 10:52:03
On Wed, 15 Mar 1995, Hamburger Dani wrote: > How do I pass an option to a new graphics function I define? > For example: > > LogLogListPlot[x_List] := > ListPlot[Transpose[ {Log[10,Transpose[x][[1]]],Log[10,Transpose[x][[2]]]} ] ] ; > > But I would like to have plot-labels as well, so > LogLogListPlot[x,PlotLabel->"xxx"] should work. How do I extend the definition > of LogLogListPlot to enable this? > > Thanks for any suggestions, Here's one way: Needs["ProgrammingExamples`FilterOptions`"] (* standard Mathematica package *) ? FilterOptions FilterOptions[symbol, options...] returns a sequence of those options that are valid options for symbol. FilterOptions[ Plot, Frame -> True, PlotDivision -> 30, whatever -> 10 ] (* "whatever" is not a valid option for Plot and is eliminated *) Sequence[Frame -> True, PlotDivision -> 30] Log[10, {{x1, y1}, {x2, y2}, {x3, y3}}] (* i.e., Log is Listable *) Log[x1] Log[y1] Log[x2] Log[y2] Log[x3] Log[y3] {{-------, -------}, {-------, -------}, {-------, -------}} Log[10] Log[10] Log[10] Log[10] Log[10] Log[10] LogLogListPlot[ data_List, opts___Rule ] := Module[ { plotOpts = FilterOptions[ Plot, opts ] }, (* additional options can be defined for LogLogListPlot but only valid Plot options are passed to ListPlot *) ListPlot[ Log[10, data], plotOpts ] ] data = Table[{k, Random[ Real, {1, 1000}]}, {k, 50}]; (* random data *) LogLogListPlot[ data, PlotLabel -> "LogLog of data", AxesLabel -> {"data", None} ]; (* all plot options are available *)