Have you seen FilterRules[]
? For instance,
Graphics[g, FilterRules[options, Options[Graphics]]]
passes only options for Graphics
. Here's an example:
ndsolvePlot // ClearAll;
ndsolvePlot // Options =
DeleteDuplicatesBy[Join[Options@NDSolve, Options@ListLinePlot], First];
ndsolvePlot[sys_, y_, dom : {_, _, _}, opts : OptionsPattern[]] :=
With[
{sols = NDSolveValue[sys, y, dom,
FilterRules[Flatten@{opts}, Options@NDSolve]]},
ListLinePlot[sols,
FilterRules[Flatten@{opts}, Options@ListLinePlot]] /;
MatchQ[sols, _InterpolatingFunction | {__InterpolatingFunction}]
];
ndsolvePlot[{y''[x] - x y[x]^4 + y[x]^7 == 0, y[0] == 1,
y'[0] == -1}, y, {x, 0, 10}, Method -> "ExplicitRungeKutta",
Frame -> True]
ndsolvePlot[{y''[x] - x y[x]^4 + y[x]^7 == 0, y[0] == 1,
y'[0] == -1}, y, {x, 0, 10}, Frame -> True, PlotRange -> All]
If you want the default settings for options for the custom function ndsolvePlot[]
to be different than the defaults for the components, NDSolve[]
or ListLinePlot[]
, then the FilterRules[]
calls should look like this:
FilterRules[Flatten@{opts, Options@ndsolvePlot}, Options@NDSolve]
FilterRules[Flatten@{opts, Options@ndsolvePlot}, Options@ListLinePlot]
Note I did not handle conflicting option values above. For instance the default InterpolationOrder
option values are different. The one for ListLinePlot[]
is InterpolationOrder -> None
and does not work in NDSolve[]
. And the default for NDSolve[]
, InterpolationOrder -> Automatic
does something different than None
in ListLinePlot[]
. In an actual application, one might have to fiddle with the values to get the desired behavior. For instance, one could hard-code the respective defaults like this:
FilterRules[Flatten@{opts,
InterpolationOrder -> Automatic, Options@ndsolvePlot}, Options@NDSolve]
FilterRules[Flatten@{opts,
InterpolationOrder -> None, Options@ndsolvePlot}, Options@ListLinePlot]