Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

default options, OptionsPattern[], and FilterRules[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106466] default options, OptionsPattern[], and FilterRules[]
  • From: Roman <rschmied at gmail.com>
  • Date: Wed, 13 Jan 2010 06:00:18 -0500 (EST)

dear group,
I am trying to set up a plotting function which has a different
default behavior than the standard one. Here's a simple example:

Options[myplot] = {PlotRange -> {-5, 5}};
myplot[F_, opts : OptionsPattern[]] :=
 Plot[F, {x, -1, 1}, Evaluate[FilterRules[{opts}, Options[Plot]]]]

What I would like to achieve with this is that when I don't specify
the PlotRange option, as in
   myplot[Sin[x]]
then I would get a plot with a default plot range of {-5,5}.
Unfortunately this does not work, since the call to FilterRules[] does
not access the default rules defined in Options[myplot], but only
those options explicitly specified in opts (i.e. none at all in this
call example).

Since this seems like such a standard use of the Options framework of
Mathematica, I would expect there to be pre-defined functionality for
what I am trying to achieve. Of course I can manually merge the
contents of the opts variable with those of Options[myplot] and
eliminate duplicates, but I'd like to avoid such hacks if possible.

Do you know a simple solution for this problem?
Thanks!
Roman.


  • Prev by Date: Re: Program Generation of Mathematica Code
  • Next by Date: Re: Re: Rotate
  • Previous by thread: Button Initialization
  • Next by thread: Re: default options, OptionsPattern[], and FilterRules[]