Message Boards Message Boards


Mathematica did not display the graph

Posted 9 months ago
4 Replies
6 Total Likes

I use following codes, but the mathematica don't display the graph, how to see it ?

a1 = CompleteGraph[{4, 6}, VertexLabels -> Automatic]
EdgeAdd[a1, {11 <-> 5, 12 <-> 5, 13 <-> 5, 11 <-> 6, 12 <-> 6, 
13 <-> 6, 11 <-> 7, 12 <-> 7, 13 <-> 7}]
4 Replies

I would call this a bug. It's a fairly typical type of failure, but it is very confusing (and hard to debug) if you have not encountered it in the past.

Most graph functions have the bad habit of just refusing to work when something goes wrong, but not reporting any errors. This is what happens here.

When you create a complete multipartite graph, the graph layout is automatically set to "MultipartiteLayout". Check Options[a1, GraphLayout].

In[7]:= Options[a1, GraphLayout]

Out[7]= {GraphLayout -> {"MultipartiteLayout", 
   "VertexPartition" -> {4, 6}}}

This layout is inherited by the result of EdgeAdd. But now the graph has more vertices than 4+6=10, so the layout specification is no longer valid. Instead of indicating that something is wrong, and issuing some readable error message, Mathematica will simply not render the graph.

Workaround: set your own GraphLayout:

Graph[g, GraphLayout -> "SpringElectricalEmbedding"]

It is frustrating to see so many of these issues because anyone who actually uses this functionality area will run into these things regularly. This is why I keep repeating that development should be driven by real use cases, and feedback from users who actually use this for real work.

Posted 9 months ago

EdgeAdd appears to work, if it does not introduce any new vertices.

a1 = CompleteGraph[{2, 3}, VertexLabels -> Automatic]

EdgeAdd[a1, 2 -> 5]

It works even if it introduces new vertices. What fails is not the change to the graph but displaying the graph. This is because the number of vertices is part of the GraphLayout specification. Thus any operation that changes the number of vertices (but does not explicitly change the GraphLayout) will cause the graph to fail to draw.

Posted 9 months ago

Thanks, you are awesome. I encountered it at the first time.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract