Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

I know, this is very close to Functions with OptionsFunctions with Options and/or Function with custom Options and modified Options for built-in SymbolsFunction with custom Options and modified Options for built-in Symbols, but I don't get it.

My function looks like this one:

myPlot[data1_, data2_, opts : OptionsPattern[]] :=
 Module[{Rescaled, dataRescaled},
  Rescaled[x_, commonZero_: False] :=
   If[commonZero,
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = Rescaled[data2];
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

And this is how I want to call it:

myPlot[
 Sin[Range[51, 100, .1]],
 Cos[Range[51, 100, .1]] + 5,
 PlotLegends -> Automatic
 ]

enter image description here

But how can I add an option "CommonZero->True"?

EDIT:

I edited my function this way

myPlot[data1_, data2_, 
  opts : OptionsPattern[{ListLinePlot, Rescaled}]] :=
 Module[{Rescaled, dataRescaled},
  Options[Rescaled] = {CommonZero -> False};
  Rescaled[x_, OptionsPattern[]] :=
   If[OptionValue[CommonZero],
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = 
   Rescaled[data2, CommonZero -> OptionValue[CommonZero]];
  
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

But I doubt this is the right or a nice way to do.

I know, this is very close to Functions with Options and/or Function with custom Options and modified Options for built-in Symbols, but I don't get it.

My function looks like this one:

myPlot[data1_, data2_, opts : OptionsPattern[]] :=
 Module[{Rescaled, dataRescaled},
  Rescaled[x_, commonZero_: False] :=
   If[commonZero,
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = Rescaled[data2];
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

And this is how I want to call it:

myPlot[
 Sin[Range[51, 100, .1]],
 Cos[Range[51, 100, .1]] + 5,
 PlotLegends -> Automatic
 ]

enter image description here

But how can I add an option "CommonZero->True"?

EDIT:

I edited my function this way

myPlot[data1_, data2_, 
  opts : OptionsPattern[{ListLinePlot, Rescaled}]] :=
 Module[{Rescaled, dataRescaled},
  Options[Rescaled] = {CommonZero -> False};
  Rescaled[x_, OptionsPattern[]] :=
   If[OptionValue[CommonZero],
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = 
   Rescaled[data2, CommonZero -> OptionValue[CommonZero]];
  
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

But I doubt this is the right or a nice way to do.

I know, this is very close to Functions with Options and/or Function with custom Options and modified Options for built-in Symbols, but I don't get it.

My function looks like this one:

myPlot[data1_, data2_, opts : OptionsPattern[]] :=
 Module[{Rescaled, dataRescaled},
  Rescaled[x_, commonZero_: False] :=
   If[commonZero,
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = Rescaled[data2];
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

And this is how I want to call it:

myPlot[
 Sin[Range[51, 100, .1]],
 Cos[Range[51, 100, .1]] + 5,
 PlotLegends -> Automatic
 ]

enter image description here

But how can I add an option "CommonZero->True"?

EDIT:

I edited my function this way

myPlot[data1_, data2_, 
  opts : OptionsPattern[{ListLinePlot, Rescaled}]] :=
 Module[{Rescaled, dataRescaled},
  Options[Rescaled] = {CommonZero -> False};
  Rescaled[x_, OptionsPattern[]] :=
   If[OptionValue[CommonZero],
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = 
   Rescaled[data2, CommonZero -> OptionValue[CommonZero]];
  
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

But I doubt this is the right or a nice way to do.

deleted 10 characters in body; edited title
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

Options for own neasteda function I define that can be passed to functions I call in the definition

Options for own neasteda function I define that can be passed to functions I call in the definition

I know, this is very close to Functions with Options and/or Function with custom Options and modified Options for built-in Symbols, but I don't get it.

My function looks like this one:

myPlot[data1_, data2_, opts : OptionsPattern[]] :=
 Module[{Rescaled, dataRescaled},
  Rescaled[x_, commonZero_: False] :=
   If[commonZero,
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = Rescaled[data2];
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

And this is how I want to call it:

myPlot[
 Sin[Range[51, 100, .1]],
 Cos[Range[51, 100, .1]] + 5,
 PlotLegends -> Automatic
 ]

enter image description here

But how can I add an option "CommonZero->True"?

EDIT:

I edited my function this way

myPlot[data1_, data2_, 
  opts : OptionsPattern[{ListLinePlot, Rescaled}]] :=
 Module[{Rescaled, dataRescaled},
  Options[Rescaled] = {CommonZero -> False};
  Rescaled[x_, OptionsPattern[]] :=
   If[OptionValue[CommonZero],
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = 
   Rescaled[data2, CommonZero -> OptionValue[CommonZero]];
  
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

But I doubt this is the right or a nice way to do.

Options for own neasted functions

I know, this is very close to Functions with Options and/or Function with custom Options and modified Options for built-in Symbols, but I don't get it.

My function looks like this one:

myPlot[data1_, data2_, opts : OptionsPattern[]] :=
 Module[{Rescaled, dataRescaled},
  Rescaled[x_, commonZero_: False] :=
   If[commonZero,
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = Rescaled[data2];
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

And this is how I want to call it:

myPlot[
 Sin[Range[51, 100, .1]],
 Cos[Range[51, 100, .1]] + 5,
 PlotLegends -> Automatic
 ]

enter image description here

But how can I add an option "CommonZero->True"?

EDIT:

I edited my function this way

myPlot[data1_, data2_, 
  opts : OptionsPattern[{ListLinePlot, Rescaled}]] :=
 Module[{Rescaled, dataRescaled},
  Options[Rescaled] = {CommonZero -> False};
  Rescaled[x_, OptionsPattern[]] :=
   If[OptionValue[CommonZero],
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = 
   Rescaled[data2, CommonZero -> OptionValue[CommonZero]];
  
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

But I doubt this is the right or a nice way to do.

Options for a function I define that can be passed to functions I call in the definition

I know, this is very close to Functions with Options and/or Function with custom Options and modified Options for built-in Symbols, but I don't get it.

My function looks like this one:

myPlot[data1_, data2_, opts : OptionsPattern[]] :=
 Module[{Rescaled, dataRescaled},
  Rescaled[x_, commonZero_: False] :=
   If[commonZero,
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = Rescaled[data2];
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

And this is how I want to call it:

myPlot[
 Sin[Range[51, 100, .1]],
 Cos[Range[51, 100, .1]] + 5,
 PlotLegends -> Automatic
 ]

enter image description here

But how can I add an option "CommonZero->True"?

EDIT:

I edited my function this way

myPlot[data1_, data2_, 
  opts : OptionsPattern[{ListLinePlot, Rescaled}]] :=
 Module[{Rescaled, dataRescaled},
  Options[Rescaled] = {CommonZero -> False};
  Rescaled[x_, OptionsPattern[]] :=
   If[OptionValue[CommonZero],
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = 
   Rescaled[data2, CommonZero -> OptionValue[CommonZero]];
  
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

But I doubt this is the right or a nice way to do.

added 738 characters in body
Source Link
Phab
  • 1.6k
  • 9
  • 15

I know, this is very close to Functions with Options and/or Function with custom Options and modified Options for built-in Symbols, but I don't get it.

My function looks like this one:

myPlot[data1_, data2_, opts : OptionsPattern[]] :=
 Module[{Rescaled, dataRescaled},
  Rescaled[x_, commonZero_: False] :=
   If[commonZero,
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = Rescaled[data2];
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

And this is how I want to call it:

myPlot[
 Sin[Range[51, 100, .1]],
 Cos[Range[51, 100, .1]] + 5,
 PlotLegends -> Automatic
 ]

enter image description here

But how can I add an option "CommonZero->True"?

EDIT:

I edited my function this way

myPlot[data1_, data2_, 
  opts : OptionsPattern[{ListLinePlot, Rescaled}]] :=
 Module[{Rescaled, dataRescaled},
  Options[Rescaled] = {CommonZero -> False};
  Rescaled[x_, OptionsPattern[]] :=
   If[OptionValue[CommonZero],
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = 
   Rescaled[data2, CommonZero -> OptionValue[CommonZero]];
  
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

But I doubt this is the right or a nice way to do.

I know, this is very close to Functions with Options and/or Function with custom Options and modified Options for built-in Symbols, but I don't get it.

My function looks like this one:

myPlot[data1_, data2_, opts : OptionsPattern[]] :=
 Module[{Rescaled, dataRescaled},
  Rescaled[x_, commonZero_: False] :=
   If[commonZero,
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = Rescaled[data2];
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

And this is how I want to call it:

myPlot[
 Sin[Range[51, 100, .1]],
 Cos[Range[51, 100, .1]] + 5,
 PlotLegends -> Automatic
 ]

enter image description here

But how can I add an option "CommonZero->True"?

I know, this is very close to Functions with Options and/or Function with custom Options and modified Options for built-in Symbols, but I don't get it.

My function looks like this one:

myPlot[data1_, data2_, opts : OptionsPattern[]] :=
 Module[{Rescaled, dataRescaled},
  Rescaled[x_, commonZero_: False] :=
   If[commonZero,
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = Rescaled[data2];
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

And this is how I want to call it:

myPlot[
 Sin[Range[51, 100, .1]],
 Cos[Range[51, 100, .1]] + 5,
 PlotLegends -> Automatic
 ]

enter image description here

But how can I add an option "CommonZero->True"?

EDIT:

I edited my function this way

myPlot[data1_, data2_, 
  opts : OptionsPattern[{ListLinePlot, Rescaled}]] :=
 Module[{Rescaled, dataRescaled},
  Options[Rescaled] = {CommonZero -> False};
  Rescaled[x_, OptionsPattern[]] :=
   If[OptionValue[CommonZero],
    (* for an common zero line *)
    x - 5,
    (* normal *)
    x
    ];
  dataRescaled = 
   Rescaled[data2, CommonZero -> OptionValue[CommonZero]];
  
  ListLinePlot[{data1, dataRescaled},
   FilterRules[{opts}, Options[ListLinePlot]],
   PlotLegends -> {"should not", "be the legend"}]
  ]

But I doubt this is the right or a nice way to do.

Source Link
Phab
  • 1.6k
  • 9
  • 15
Loading