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
]
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[myPlot] = Sort[Append[Options[Plot], "CommonZero" -> True]]
and useOptionValue[]
andFilterRules[]
as necessary. $\endgroup$Rescaled
, and set up an option default list the way I did in my previous comment. $\endgroup$