4
$\begingroup$

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!

$\endgroup$
  • $\begingroup$ Do you want the $z\geq 0$ to be any number, or some in particular? $\endgroup$ – corey979 Sep 24 '16 at 14:47
  • $\begingroup$ I want the $z \geq 0$ to be any number. $\endgroup$ – Gagar Sep 24 '16 at 14:50
  • $\begingroup$ Then maybe just rules = Join[Table[i -> {Automatic, Automatic, 0}, {i, 1, 4}], Table[i -> {Automatic, Automatic, RandomReal[1]}, {i, 5, 16}]];? $\endgroup$ – corey979 Sep 24 '16 at 14:51
  • $\begingroup$ 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". $\endgroup$ – Gagar Sep 24 '16 at 14:53
  • $\begingroup$ Can the negative $z$ from your GraphPlot3D be simply transformed to $|z|$? $\endgroup$ – corey979 Sep 24 '16 at 15:08
1
$\begingroup$

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? !

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Szabolcs Sep 24 '16 at 22:50
  • $\begingroup$ That's strange, I'm using igraph version 0.7.1 which seems to have these options. $\endgroup$ – Gagar Sep 24 '16 at 23:17
  • $\begingroup$ 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. $\endgroup$ – Szabolcs Sep 25 '16 at 9:12

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.