Message Boards Message Boards

GROUPS:

Retaining vertex labels

Posted 10 years ago
5623 Views
|
2 Replies
|
1 Total Likes
|
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 10 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