When looking at the internals of graphics expressions we often see that some options like PlotRange
, Frame
, Ticks
, PlotRangePadding
etc. are repeated several times in the list, and sometimes even have different values. For example:
gr = LogLogPlot[x^2 + x^3, {x, 1, 100}];
Cases[Options[gr], _[Ticks, _]]
Cases[Options[gr], _[DisplayFunction, _]]
{Ticks -> {Charting`ScaledTicks["Log", {Log, Exp}, "Nice", WorkingPrecision -> MachinePrecision, RotateLabel -> 0], Charting`ScaledTicks["Log", {Log, Exp}, "Nice", WorkingPrecision -> MachinePrecision, RotateLabel -> 0]}, Ticks -> {Automatic, Automatic}} {DisplayFunction -> Identity, DisplayFunction -> Identity, DisplayFunction -> Identity, DisplayFunction -> Identity, DisplayFunction -> Identity, DisplayFunction -> Identity, DisplayFunction :> Identity}
In the above example, the option Ticks
appears two times with different values, and the option DisplayFunction
appears 7 (!) times with identical values.
When inspecting the low-level structure of Mathematica graphics, such duplicated options litter the source code and often make it difficult to find out which value of duplicated option actually "works".
Is there a safe way to remove all the trash from the list of options, leaving only those option specifications which actually work? I know that we can obtain actual value for every particular option by specifying it explicitly in the second argument of Options
, but I wish to leave only the options which are already present in the expression.
A super-requirement would be the ability to remove non-actual options: for example, if we have set Axes -> False
, then options like AxesOrigin
, AxesStyle
, Ticks
do nothing and we can safely remove them from the expression source code for the purposes of readability.
UPDATE
I just found that Options
has a bug: it extracts options from the first argument of Graphics
too, for example:
gr = Graphics[{Ticks -> Automatic, AspectRatio -> 1},
{Axes -> True}, {{Ticks -> {Automatic, None}}}, Ticks -> Automatic, AspectRatio -> .2]
Options[gr, {Ticks, AspectRatio}]
{Ticks -> Automatic, AspectRatio -> 1}
As one can see, Options
takes the requested option values from the first argument of Graphics
- where they are ignored by the renderer!