What is the most convenient way to change options such as VertexLabels in existing Graph objects? (Version 7 users note: Graph is new in Mathematica 8.)
With graphics, we can use Show for this, not matter what function was originally used to produce the graphic:
g = Plot[Sin[x], {x, 0, 10}]
Show[g, Axes -> False, Frame -> True]
Is there an analogous function for Graphs? Suppose we already have a graph, and now we need to show vertex labels in a different way.
Here's a workaround using HighlightGraph:
g = Graph[{1 -> 2}]
HighlightGraph[g, {}, VertexLabels -> "Name"]
While it works, this is not really what HighlightGraph is meant for.
Please note that Graph objects are atomic before trying to take them apart. Also, I'm looking for the safest and most robust solution. I'm hoping there's a function I overlooked.
Answer
You could use SetProperty. For example
g = Graph[{1 -> 2, 2 -> 4, 3 -> 4}]
SetProperty[g, VertexLabels -> {"Name", 2 -> "Two"}]

Comments
Post a Comment