I stumbled (here, in the expression for the block diagram) upon a version of Graph that I don't see in the documentation over here. That documentation admits three overloads (the following are in my own words):

  1. Graph[{edges}]
  2. Graph[{vertices}, {edges}]
  3. Graph[{decoratedVertices}, {decoratedEdges}]

For instance, the following example invokes overload 2:

Graph[{1,2,3}, {{1, 2}, {1, 3}, {2, 3}}]

enter image description here

If I add a Null in an undocumented place, I get arrows:

Graph[{1,2,3}, { {{1, 2}, {1, 3}, {2, 3}}, Null } ]

Notice there is an extra level of List in the list of vertices. It's as though the list of vertices contains a nested list of vertices and a Null vertex.

This seems to produce similar results to

Graph[{1, 2, 3}, {1 \[DirectedEdge] 2, 1 \[DirectedEdge] 3, 2 \[DirectedEdge] 3}]

Anyone happen to know what's going on? I'm ok with blindly using the cool feature, but I wonder what the other options for this API might be.

enter image description here


This seems to give you the format:

Graph[ {vertices}, { directededges, undirectededges} ]

For example, try changing up what you have to include non-null entries:

Graph[{1, 2, 3}, { {{1, 2},{2, 3},{1, 3}}, {{3, 2}} }]

Graph[{1, 2, 3}, { {{1, 2},{2, 3}}, {{3, 2},{1, 3}} }]


It still falls under category "2" from your list, more or less. I don't see this in the documentation, but that may be because it's just a bit of an odd feature.

So, as further example, you could take:

Graph[{1, 2, 3}, {{{2, 3}}, {{1, 2}, {3, 1}}}]

which is the same as:

Graph[{1 <-> 2, 2 -> 3, 3 <-> 1}]

However, one important difference I noticed is that it's actually hard to use the syntax you've discovered because it doesn't play nicely with other options:

Graph[{1 <-> 2, 2 -> 3, 3 <-> 1},, EdgeStyle -> {3 <-> 1 -> Red}]

will return a nice graph with one red edge and one directed edge. However:

Graph[{1, 2, 3}, {{{2, 3}}, {{1, 2}, {3, 1}}},EdgeStyle -> {{3,1} -> Red}]

will not do this. (I haven't found a variation on EdgeStyle type options that allow you to specify styles for this double-list of directed & undirected edges.) I suspect that this double-list format to specify directed vs. undirected edges may be a sort of legacy format that was built into the Graph command in previous versions, although I don't find documentation offhand showing this syntax in the old Combiantorica package (although there's a huge volume of documentation for Combinatorica and the transition to the newer built-in functions, not to mention Combinatorica may have included undocumented properties).

Here's another example to play with:

m = 5;
de = Table[{RandomInteger[{1, m}], RandomInteger[{1, m}]}, {i, 1, m^2/4}];
ue = Table[{RandomInteger[{1, m}], RandomInteger[{1, m}]}, {i, 1, m^2/4}];
Graph[Range[m], {de, ue}]

This just makes random lists of edges. You can vary m to make the graph bigger or smaller.

| improve this answer | |

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.