Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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. – Szabolcs Apr 20 '12 at 13:20
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. – Szabolcs Apr 20 '12 at 13:21
up vote 3 down vote accepted

The following works:

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};

enter image description here

share|improve this answer
 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]]


enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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