I am puzzled by how AbsoluteOptions
works with Graph
objects. I would have expected that one could use it to obtain all the options used to draw a graph. There are several ways in which it behaves contrary to my expectations.
First, let' s make a simple graph, g, and set some custom options:
g = RandomGraph[{6, 11}, VertexStyle -> {1 -> Red, 2 -> Green},
VertexSize -> {1 -> Large, 2 -> Large}, VertexLabels -> "Name",
ImagePadding -> 15, EdgeLabels -> "Name", Axes -> True]
1 - Why won' t all the options work again?
One expects that the options used for g
could be obtained through AbsoluteOptions[g]
and redeployed. However, this does not work. Either the code below locks up completely or the Out cell has a tooltip: "$Failed is not a Graphics primitive or directive".
allOptions = AbsoluteOptions[g];
g2 = Graph[EdgeList[g], allOptions]
2 - Some options work as expected, others do not. Why?
Let's take a subset of the options of g
; namely, {VertexCoordinates, EdgeLabels, Axes, VertexLabels, VertexSize, AlignmentPoint, ImagePadding}
. Now let's compare g and the partial replication, g3, side by side:
someOptions =
Sort@AbsoluteOptions[
g, {VertexCoordinates, EdgeLabels, Axes, VertexLabels, VertexSize,
AlignmentPoint, ImagePadding}]
g;
g3 = Graph[EdgeList[g], someOptions]
someOptions3 =
Sort@AbsoluteOptions[
g3, {VertexCoordinates, EdgeLabels, Axes, VertexLabels, VertexSize,
AlignmentPoint, ImagePadding}]
(* Out someOptions3*)
{AlignmentPoint -> Center, Axes -> {True, True},
EdgeLabels -> {"Name"}, ImagePadding -> 15.,
VertexCoordinates -> {{0.518253, 0.817802}, {1.61587,
0.866512}, {2.05896, 0.336143}, {1.03973, 1.21024}, {1.04431, 0.}, {0., 0.377097}},
VertexLabels -> {"Name"},
VertexSize -> {1 -> Large, 2 -> Large}}
The vertex sizes are the same in each case, as expected. Also, the VertexStyle
is different. That's fine: g3 has the default vertex style.
But why are the vertices in different locations? After all, we passed the VertexCoordinates
option to g3. And the vertex coordinates returned by AbsoluteOptions[g3...
do not correspond to the coordinates used for the vertices.
3 - What are failed options?
If we inspect the options used by g, we will notice that two of them failed, even though g
was drawn with no apparent issues.
AbsoluteOptions[g, {VertexShapeFunction, EdgeShapeFunction}]
(* Out *)
{VertexShapeFunction -> $Failed, EdgeShapeFunction -> $Failed}
If you look at the graph, g, you see that the default vertex shapes and edge shapes were correctly rendered? So, whence the fail?
4 - Why is it insufficient to remove failed options?
If we remove the failed options and try to implement all the other options, MMA does one of two things: (1) It returns the unparsed Graph
command or (2) it produces only a small portion of the graph, g.
Any help would be appreciated. I'm not trying to correct a particular program but rather understand the strengths and limitations of AbsoluteOptions.