Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6947121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:39:13+00:00 2026-05-27T13:39:13+00:00

This should be quick to an expert, but I’m relatively new at defining functions

  • 0

This should be quick to an expert, but I’m relatively new at defining functions with options. Here is a schematic of what I’ve tried, I’ll explain after showing the code:

MyPlotFunction[params_, optionalparameter_List:{1,2,3}, opts:OptionsPattern[]]:=
    Plot [ stuff, {x,0,1},  Evaluate@FilterRules[{opts},Options@Plot]];

Options[MyPlotFunction] = {  PlotRange->{-5,5}, Frame->True, ... other plot options};

There are four slight subtleties:

  1. I have an optional parameter in my function that needs to be a list of integers.
  2. I want the ability to call the function with any option of Plot, especially using values other than the default values specified in the third line.
  3. I want to have default values for some of the options.
  4. I potentially want to put other options in the function, so it is not guaranteed that all of the options should be passed through to plot.

But what I have above doesn’t work. The default options I set are ignored, yet they appear in the ??MyPlotFunction information for my function. I’ll give examples if you guys can’t spot the error yet.

Edit:
Examples that doesn’t work:

  1. SimplePlot[t_,opts:OptionsPattern[{PlotRange->{-4,4},Frame->True}]]:=
    Plot[2x+t,{x,0,1},opts];

    Fails, the default option is ignored.

  2. SimplePlot[t_,opts:OptionPattern[]]:=
    Plot[2x+t],{x,0,1},opts];
    Options[SimplePlot] = {PlotRange->{-4,4},Frame->True};

    Fails, the default option is ignored.

  3. SimplePlot[t_,opts__:{PlotRange->{-4,4},Frame->True}]:=
    Plot[2x+t,{x,0,1},opts];

    Default options work with a bare call, but if one of these options or any other plot option is overridden the remaining defaults are lost.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:39:14+00:00Added an answer on May 27, 2026 at 1:39 pm

    OptionsPattern[] only catches the options that are passed in, so you need to explicitly include any non-default option settings, say by using something like:

    FilterRules[{opts, Options[MyPlotFunction]}, Options@Plot]
    

    Here’s a simple example:

    Options[MyPlotFunction] = {PlotRange -> {-5, 5}, Frame -> True};
    
    MyPlotFunction[params_, optionalparameter_List: {1, 2, 3}, 
      opts : OptionsPattern[MyPlotFunction]] := 
     Plot[optionalparameter, {x, 0, 1}, 
      Evaluate@FilterRules[{opts, Options[MyPlotFunction]}, Options@Plot]]
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be a quick one... here is my current .htaccess file: # BEGIN
This should be relatively simple, here is my situation; I have copied the trunk
Hopefully this should be a quick one to solve but - I'm building a
This should a quick question for some easy rep. I'm doing some PHP Website
Two quick questions if I may, is this how I should go about taking
This should be a really really simple thing, but for some reason it is
This should be easy for many of you, but for me it's just another
This should be easy, but I'm not sure how to best go about it.
This should be a simple question, but I haven't been able to find a
This should hopefully be a quick one. I have a StringBuilder like so: StringBuilder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.