Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Use this answer by Yaroslav Bulatovthis answer by Yaroslav Bulatov.

test = LayeredGraphPlot[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4,
2 -> 4, 1 -> 5}, VertexLabeling -> True, ImageSize -> 200]
getLabelCoordinateMap[gp1_] := 
Module[{points, labels, actualLabels, coordAliases, actualCoords}, 
points = 
Cases[gp1, GraphicsComplex[points_, __] :> points, Infinity] // 
 First;
 labels = Cases[gp1, Text[___], Infinity];
actualLabels = labels[[All, 1, 1]];
coordAliases = labels[[All, 2]];
actualCoords = points[[coordAliases]];
Thread[actualLabels -> actualCoords]];

coord = getLabelCoordinateMap[test]
Graph[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4, 2 -> 4, 1 -> 5}, 
ImageSize -> 200, VertexLabels -> (# -> # & /@ Range@5), 
VertexCoordinates -> coord, ImagePadding -> 10]

It gives the following:

Mathematica graphics

Use this answer by Yaroslav Bulatov.

test = LayeredGraphPlot[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4,
2 -> 4, 1 -> 5}, VertexLabeling -> True, ImageSize -> 200]
getLabelCoordinateMap[gp1_] := 
Module[{points, labels, actualLabels, coordAliases, actualCoords}, 
points = 
Cases[gp1, GraphicsComplex[points_, __] :> points, Infinity] // 
 First;
 labels = Cases[gp1, Text[___], Infinity];
actualLabels = labels[[All, 1, 1]];
coordAliases = labels[[All, 2]];
actualCoords = points[[coordAliases]];
Thread[actualLabels -> actualCoords]];

coord = getLabelCoordinateMap[test]
Graph[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4, 2 -> 4, 1 -> 5}, 
ImageSize -> 200, VertexLabels -> (# -> # & /@ Range@5), 
VertexCoordinates -> coord, ImagePadding -> 10]

It gives the following:

Mathematica graphics

Use this answer by Yaroslav Bulatov.

test = LayeredGraphPlot[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4,
2 -> 4, 1 -> 5}, VertexLabeling -> True, ImageSize -> 200]
getLabelCoordinateMap[gp1_] := 
Module[{points, labels, actualLabels, coordAliases, actualCoords}, 
points = 
Cases[gp1, GraphicsComplex[points_, __] :> points, Infinity] // 
 First;
 labels = Cases[gp1, Text[___], Infinity];
actualLabels = labels[[All, 1, 1]];
coordAliases = labels[[All, 2]];
actualCoords = points[[coordAliases]];
Thread[actualLabels -> actualCoords]];

coord = getLabelCoordinateMap[test]
Graph[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4, 2 -> 4, 1 -> 5}, 
ImageSize -> 200, VertexLabels -> (# -> # & /@ Range@5), 
VertexCoordinates -> coord, ImagePadding -> 10]

It gives the following:

Mathematica graphics

deleted 33 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k

Use http://stackoverflow.com/questions/4245946/vertexcoordinate-rules-and-vertexlist-from-graphplot-graphic/4250069#4250069 from Yaroslav Bulatovthis answer by Yaroslav Bulatov.

test = LayeredGraphPlot[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4,
2 -> 4, 1 -> 5}, VertexLabeling -> True, ImageSize -> 200]
getLabelCoordinateMap[gp1_] := 
Module[{points, labels, actualLabels, coordAliases, actualCoords}, 
points = 
Cases[gp1, GraphicsComplex[points_, __] :> points, Infinity] // 
 First;
 labels = Cases[gp1, Text[___], Infinity];
actualLabels = labels[[All, 1, 1]];
coordAliases = labels[[All, 2]];
actualCoords = points[[coordAliases]];
Thread[actualLabels -> actualCoords]];

coord = getLabelCoordinateMap[test]
Graph[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4, 2 -> 4, 1 -> 5}, 
ImageSize -> 200, VertexLabels -> (# -> # & /@ Range@5), 
VertexCoordinates -> coord, ImagePadding -> 10]

Gives enter image description hereIt gives the following:

Mathematica graphics

Use http://stackoverflow.com/questions/4245946/vertexcoordinate-rules-and-vertexlist-from-graphplot-graphic/4250069#4250069 from Yaroslav Bulatov.

test = LayeredGraphPlot[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4,
2 -> 4, 1 -> 5}, VertexLabeling -> True, ImageSize -> 200]
getLabelCoordinateMap[gp1_] := 
Module[{points, labels, actualLabels, coordAliases, actualCoords}, 
points = 
Cases[gp1, GraphicsComplex[points_, __] :> points, Infinity] // 
 First;
 labels = Cases[gp1, Text[___], Infinity];
actualLabels = labels[[All, 1, 1]];
coordAliases = labels[[All, 2]];
actualCoords = points[[coordAliases]];
Thread[actualLabels -> actualCoords]];

coord = getLabelCoordinateMap[test]
Graph[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4, 2 -> 4, 1 -> 5}, 
ImageSize -> 200, VertexLabels -> (# -> # & /@ Range@5), 
VertexCoordinates -> coord, ImagePadding -> 10]

Gives enter image description here

Use this answer by Yaroslav Bulatov.

test = LayeredGraphPlot[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4,
2 -> 4, 1 -> 5}, VertexLabeling -> True, ImageSize -> 200]
getLabelCoordinateMap[gp1_] := 
Module[{points, labels, actualLabels, coordAliases, actualCoords}, 
points = 
Cases[gp1, GraphicsComplex[points_, __] :> points, Infinity] // 
 First;
 labels = Cases[gp1, Text[___], Infinity];
actualLabels = labels[[All, 1, 1]];
coordAliases = labels[[All, 2]];
actualCoords = points[[coordAliases]];
Thread[actualLabels -> actualCoords]];

coord = getLabelCoordinateMap[test]
Graph[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4, 2 -> 4, 1 -> 5}, 
ImageSize -> 200, VertexLabels -> (# -> # & /@ Range@5), 
VertexCoordinates -> coord, ImagePadding -> 10]

It gives the following:

Mathematica graphics

Source Link
Lou
  • 4.1k
  • 23
  • 28

Use http://stackoverflow.com/questions/4245946/vertexcoordinate-rules-and-vertexlist-from-graphplot-graphic/4250069#4250069 from Yaroslav Bulatov.

test = LayeredGraphPlot[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4,
2 -> 4, 1 -> 5}, VertexLabeling -> True, ImageSize -> 200]
getLabelCoordinateMap[gp1_] := 
Module[{points, labels, actualLabels, coordAliases, actualCoords}, 
points = 
Cases[gp1, GraphicsComplex[points_, __] :> points, Infinity] // 
 First;
 labels = Cases[gp1, Text[___], Infinity];
actualLabels = labels[[All, 1, 1]];
coordAliases = labels[[All, 2]];
actualCoords = points[[coordAliases]];
Thread[actualLabels -> actualCoords]];

coord = getLabelCoordinateMap[test]
Graph[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4, 2 -> 4, 1 -> 5}, 
ImageSize -> 200, VertexLabels -> (# -> # & /@ Range@5), 
VertexCoordinates -> coord, ImagePadding -> 10]

Gives enter image description here