Define function that behaves almost identically to Mathematica function
If you want to constrain it to only options from ListPlot
, you could use OptionsPattern
in combination with FilterRules
and Options
.
myListPlot[data_, opts : OptionsPattern[]] :=
ListPlot[data, GridLines -> {None, {data[[1]]}},
FilterRules[{opts}, Options[ListPlot]]]
which results in:
myListPlot[data, PlotStyle -> Red, Joined -> True]
The usual way to define a Wolfram Language function that takes n
arguments and an arbitrary number of options is like this:
f[arg1_, ..., argn_, opts___] := ...
A little bit of pattern matching background (taken from the WL reference):
_
any single expressionx_
any single expression, to be namedx
__
any sequence of one or more expressionsx__
sequence namedx
x__h
sequence of expressions, all of whose heads areh
___
any sequence of zero or more expressionsx___
sequence of zero or more expressions namedx
x___h
sequence of zero or more expressions, all of whose heads areh