Message Boards Message Boards

0
|
6733 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Retaining vertex labels

Posted 11 years ago
Hello,
With
g = Graph[{"alice" -> "bertram", "carl" -> "bertram"}, VertexLabels -> "Name"]

I get a graph with meaningful labels but with
LayeredGraphPlot[g, VertexLabeling -> True]
the labels are replaced with 1,2,3. How can I keep my names for the vertices as names rather than indices?
POSTED BY: Erik Itter
2 Replies
Posted 11 years ago
thx, that works for me
POSTED BY: Erik Itter
Mathematica had a set of functions for graph plotting before it had the Graph[] data type.  So now we have two separate and slightly different ways to visualize graphs.  LayeredGraphPlot is one of the older set.

If you use the new method, then the names will be retained.  You just need to set the GraphLayout option:
SetProperty[g, GraphLayout -> "LayeredEmbedding"] // Show

I used Show as a workaround for the cut off labels around the edges, otherwise it's not necessary.  What it does is that it converts the graph to graphics.
POSTED BY: Szabolcs Horvát
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract