7
$\begingroup$

My question is concerned with the Graph functionality, which was newly implemented in Mathematica 8. I already used GraphPlot and LayeredGraphPlot in the previous versions and in principle appreciate the new capabilities. However, I still wonder if the current implementation is complete. E.g. in the code below, I try to use VertexCoordinates for each vertex, which according to the documentation for Graph, should work.

vertices1 = {
   Property[1, {VertexCoordinates -> {0, 3}, VertexSize -> 0.3}],
   Property[2, VertexCoordinates -> {1, 2}],
   Property[3, VertexCoordinates -> {3, 3}]
 };

Graph[vertices1, {1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3},  GraphLayout -> {"LayeredDrawing", "LayeredLeft"}]

Other Options within Property, e.g. VertexSize, work correctly. VertexCoordinates has no effect whatsoever. VertexCoordinates will work as an option for Graph, but not as a Property for a particular vertex.

My other concern relates to GraphLayout and in particular to the Suboption "PackingLayout", which also seems to have no influence whatsoever. E.g. if I use "LayeredDrawing", the Suboptions "LayeredLeft" or "LayeredTop" create the same Graph.

What is your experience?

$\endgroup$
  • $\begingroup$ I don't know why Property doesn't work here. As far as I understand the docs, it should. As you noticed, one workaround is using VertexCoordinates as an option to Graph. Another one is setting vertex coordinates after the graph has been built. $\endgroup$ – Szabolcs Apr 20 '12 at 13:20
  • $\begingroup$ Regarding "PackingLayout": as I understand, it is relevant only if the graph is not connected (i.e. it has several connected components). The components will be laid out separately, then the "PackingOption" method will be used to lay out the separate components on the canvas. $\endgroup$ – Szabolcs Apr 20 '12 at 13:21
3
$\begingroup$

The following works:

ClearAll[g];
vertices1 = {1, 2, 3};
g = Graph[vertices1, {1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3}];
PropertyValue[{g, 1}, VertexSize] = .3;
PropertyValue[{g, 1}, VertexCoordinates] = {0, 3}; 
PropertyValue[{g, 2}, VertexCoordinates] = {1, 2};
PropertyValue[{g, 3}, VertexCoordinates] = {3, 3};
g

enter image description here

| improve this answer | |
$\endgroup$
3
$\begingroup$
 vertices1 = {Property[1, {VertexSize -> 0.3}], 2, 3};
 coordlist = {{0, 3}, {1, 2}, {3, 3}};
 g1 = Graph[vertices1, {1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3}, 
    GraphLayout -> {"LayeredDrawing", "LayeredLeft"}];
 Fold[SetProperty[{#1, #2}, 
   VertexCoordinates -> coordlist[[VertexIndex[#1, #2]]]] &, g1, VertexList[g1]]

gives

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.