2
$\begingroup$

Suppose I have a graph like this

Graph[ {1 <-> 2, 2 <-> 3, Labeled[3 <-> 1, "hello"]}, VertexLabels -> Placed["Name",StatusArea] ] 

Now I want to add more properties to all the nodes.

For instance, I want to replace name of node 1 by number 3700, node 2 by 3701, node3 by 3703 and those should be displayed only in the status area.

Along with replacing the node names, I also want some more properties associated with nodes. For instance, I'd like 3700, "h1" to be displayed in the status area when I place my mouse pointer at node 1; at node 2, it should display 3700, "h2" etc. (not exactly those but some other display stuff).

How can I do it?

$\endgroup$

1 Answer 1

5
$\begingroup$

Set a graph with properties:

g = Graph[{Property[1, "Custom" -> {3700, "h1"}], Property[2, "Custom" -> {3700, "h2"}], Property[3, "Custom" -> {3700, "h2"}]}, {1 <-> 2, 2 <-> 3, 3 <-> 1}]; 

Define labels:

labels = # -> Placed[ToString[PropertyValue[{g, #}, "Custom"], InputForm], StatusArea] & /@ VertexList[g]; 

Draw graph:

SetProperty[g, VertexLabels -> labels] 

enter image description here

$\endgroup$
2
  • $\begingroup$ Hi @halmir, thanks for the answer. But I have a graph which has a very large number of nodes. So I cannot really write the property for every vertex. Is there any way I can generalize the code for all of them? $\endgroup$ Commented Jan 26, 2016 at 20:21
  • $\begingroup$ Yes, you can. You can just map properties over you vertices. What do you have? $\endgroup$ Commented Jan 27, 2016 at 0:24

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.