Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
up vote 14 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[]] := 
  sol = NDSolve[de, y, {x, x0, x1}, 
    FilterRules[{opts}, Options[NDSolve]]];
  If[Head[sol] === NDSolve,
   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


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.