Mathematica Subgraph "Neat Example" not working properly in Mathematica 12
sg = Subgraph[g,
Complement[VertexList[g],
VertexList[NeighborhoodGraph[g, RandomSample[VertexList[g], 25], 1]]]];
The issue seems to be that Subgraph
inherits the GraphLayout
option value from the parent graph:
PropertyValue[sg, GraphLayout]
{"GridEmbedding", "Dimension" -> {25, 50}}
and, somehow, the vertex layout defaults to something weird when the number of vertices do not match the length of the coordinate list produced by the layout procedure.
So, you can
- add the option
GraphLayout -> Automatic
(or use your desired setting):
SetProperty[sg, GraphLayout -> "SpringElectricalEmbedding"]
- remove the
GraphLayout
property fromg
:
Subgraph[RemoveProperty[g, GraphLayout],
Complement[VertexList[g],
VertexList[NeighborhoodGraph[g, RandomSample[VertexList[g], 25], 1]]]]
- use the option
VertexCoordinates
to retain vertex coordinates ing
:
Subgraph[g,
Complement[VertexList[g],
VertexList[NeighborhoodGraph[g, RandomSample[VertexList[g], 25], 1]]],
VertexCoordinates -> {v_ :> PropertyValue[{g, v}, VertexCoordinates]}]
How about filing a bug with Wolfram Research? It only takes a few minutes. In a notebook, click Help, Give feedback..., fill out the rest of the form (most is completed for you), and then click "Submit." You don't need a service contract to file a bug, and there is no guarantee the Wolfram will see this Stack Exchange entry.