Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How do you combine OptionsPatterns?

For example, I would like to have a function that can take both options that I specify, and options for all graphs:

Options[f]={"a"->b} + OptionsPattern[LogPlot]
f[...,OptionsPattern[]] := LogPlot[..., ImageSize->OptionsValue[ImageSize]]

A related question, how do I remove options from an OptionsPattern, and pass on the remainder to another function.

For example:

f[...,OptionsPattern[LogPlot]] := LogPlot[..., (* pass on all the options EXCEPT Frame *)]

Thanks for the help.

share|improve this question
1  
A somewhat related question with very good answers –  Ryogi Aug 31 '12 at 23:39
    
@Ryogi: Thanks! That has a great answer for me. –  Andrew Spott Sep 1 '12 at 16:34

2 Answers 2

up vote 12 down vote accepted

This information is given in the tutorial Setting Up Functions with Optional Arguments. Just catch the options given to your function in a variable and use FilterRules

odeplot[de_, y_, {x_, x0_, x1_}, opts : OptionsPattern[]] := 
 Module[{sol},
  sol = NDSolve[de, y, {x, x0, x1}, 
    FilterRules[{opts}, Options[NDSolve]]];
  If[Head[sol] === NDSolve,
   $Failed,
   Plot[Evaluate[y /. sol], {x, x0, x1}, 
    Evaluate[FilterRules[{opts}, Options[Plot]]]]
   ]
  ]
share|improve this answer

For your "related question", of passing all options to LogPlot other than Frame, just set the option to the value you want, and place this first in the function call. The first occurrence of the option is used, so any use of it in opts is redundant and ignored.

f[data_, opts:OptionsPattern[]]:= LogPlot[data, Frame->False, 
  Evaluate[FilterRules[{opts},Options[LogPlot]]] ]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.