4

Is there a way to impose various conditions on the positions of the vertices when embedding a graph using GraphPlot3D? More precisely, I have a graph g, which I want to embed using GraphPlot3D in such a way that several vertices have $z$ coordinate with $z=0$ and the other vertices have $z$ coordinate with $z \geq 0$.

In the following example, I get the $z=0$ condition for the first $4$ vertices, but I can't manage to impose the $z \geq 0$ condition for the others.

graph = {1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 1 -> 5, 1 -> 3, 1 -> 4, 2 -> 6, 3 -> 6, 1 -> 6, 1 -> 7, 2 -> 7, 6 -> 8, 1 -> 8, 5 -> 9, 1 -> 9, 4 -> 9, 4 -> 10, 5 -> 10, 9 -> 10, 9 -> 11, 4 -> 11, 4 -> 14, 9 -> 14, 9 -> 15, 11 -> 15, 11 -> 14};

rules = Join[Table[i -> {Automatic, Automatic, 0}, {i, 1, 4}], Table[i -> {Automatic, Automatic, Automatic}, {i, 5, 16}]];

GraphPlot3D[graph, VertexCoordinateRules -> rules, Method -> "SpringElectricalEmbedding"]

Many thanks in advance!

Gagar
  • 151
  • 2
  • Do you want the $z\geq 0$ to be any number, or some in particular? – corey979 Sep 24 '16 at 14:47
  • I want the $z \geq 0$ to be any number. – Gagar Sep 24 '16 at 14:50
  • Then maybe just rules = Join[Table[i -> {Automatic, Automatic, 0}, {i, 1, 4}], Table[i -> {Automatic, Automatic, RandomReal[1]}, {i, 5, 16}]];? – corey979 Sep 24 '16 at 14:51
  • Sorry I wasn't clear enough: I do not want to constrain the $z$ coordinate to be some number, I want it to be determined by the SpringElectricalEmbedding. In other words, I would like to have "Automatic" replaced by "Automatic but nonnegative". – Gagar Sep 24 '16 at 14:53
  • Can the negative $z$ from your GraphPlot3D be simply transformed to $|z|$? – corey979 Sep 24 '16 at 15:08
  • It could, but this does not seem to give what I have in mind: I want to this for large graphs so that they seem to grow "upwards". If I do this transformation, they remain close to $z=0$, e.g. for this large graph : http://pastebin.com/3HParMGW – Gagar Sep 24 '16 at 15:31

1 Answers1

1

I finally found a way to this by using the Python library igraph with the embedding igraph_layout_fruchterman_reingold_3d (thanks to the $maxz$ and $minz$ options) and by executing a Python script in Mathematica thanks to the first answer of Is there a way to run Python from within Mathematica? !

Gagar
  • 151
  • 2
  • Actually those options are gone in the latest version of igraph, as this layout method is completely rewritten. igraph also has an R interface, which is easier to access from Mathematica through RLink. However, it is built against the latest C core and doesn't have these options any more. – Szabolcs Sep 24 '16 at 22:50
  • That's strange, I'm using igraph version 0.7.1 which seems to have these options. – Gagar Sep 24 '16 at 23:17
  • Yes, that's right. 0.7.1 has them, 0.8 won't. This is just a warning in case you'd update in the future or use the R interface. – Szabolcs Sep 25 '16 at 09:12