2
$\begingroup$

Compare following two low-level box representations of a graph without VertexLabels and one with VertexLabels set to "Name" with ToBoxes[]:

ToBoxes[Graph[{1 <-> 2}]]

ToBoxes[Graph[{1 <-> 2}, VertexLabels -> "Name"]]

(Alternatively, select visual representation and press Cmd+Shift+E on mac.)

The first one uses GraphicsComplex for an efficient representation of the graph and the second does not.

enter image description here

Is there a conceptual or technical reason for this?

I came across this trying to use this answer for a graph with VertexLabels enabled where GraphicsComplexBox[x_, y_, z___] does not match anything anymore.

Mathematica version: 11.2

$\endgroup$
  • 1
    $\begingroup$ Well, I made the experience that everything involving PropertyValues for Graphs is handled quite differently than without (and often in an inconsistent way but that's another story). This is maybe because there can be so many exceptions... And using VertexLabels also implies that your graph is not overly large so that the profit from GraphicsComplex is marginal, right? Maybe that was the thinking behind this design decision... $\endgroup$ – Henrik Schumacher Apr 13 '18 at 17:34
  • $\begingroup$ Thanks for your thoughts. I guess you are right that you only place labels when you have a graph not with thousands of vertices. Do you know if there is a way to use Normal[] or another function to get an identical representation for both? $\endgroup$ – Hotschke Apr 13 '18 at 17:44
  • $\begingroup$ Hm. AdjacencyGraph@AdjacencyMatrix should get rid of all PropertyValues. Plotting it leads to a GraphicsComplex, but the vertex lables, vertex coordinates, etc. are gone. Is that what you need? $\endgroup$ – Henrik Schumacher Apr 13 '18 at 18:37
  • $\begingroup$ You can also use H = Graph[VertexList[G], EdgeList[G]]. Depending on the internal representation of the graph (sparse or not), the one or the other may be faster. $\endgroup$ – Henrik Schumacher Apr 13 '18 at 18:42
  • 1
    $\begingroup$ I guess you are not aware of the problems of mixed (directed and undirected edges) multi-graphs pointed out by Szabolc. I try to resolve it manually. But it is very hard to do. I am little bit disappointed with Mathematica. Also Normal[Graph] does not work. The documentation sounds promising but again does not work here because the undocumented GraphicsComplexBox is used. $\endgroup$ – Hotschke Apr 13 '18 at 20:06

Your Answer

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

Browse other questions tagged or ask your own question.