Ask Your Question
0

Changing vertex labels on a randomly generated graph

asked 2016-03-03 16:06:39 +0100

dazedANDconfused gravatar image

updated 2016-06-06 21:27:22 +0100

FrédéricC gravatar image

I know that if I want to create a graph on 4 vertices with vertex labels 1,2,3,4 then I can define my graph like this: G = Graph({0: [1, 3], 1: [2, 3,4], 2: [1,4], 3: [], 4: []})

and then when I print in LaTeX using sagetex the labels show up as 1,2,3,4 but when I try to create a graph randomly graphs.RandomGNM(4,5)).show(figsize=[4,4], graph_border=True) the vertex labels are 0,1,2,3. How do I change the default vertex labels of a randomly created graph?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2016-03-03 17:13:58 +0100

tmonteil gravatar image

updated 2016-03-03 17:14:21 +0100

You can give a name to your graph and then use the relabel method:

sage: G = graphs.RandomGNM(4,5)
sage: G.vertices()
[0, 1, 2, 3]
sage: G.relabel({0:'zero' , 1:'one', 2:'two', 3:'three'})
sage: G.vertices()
['one', 'three', 'two', 'zero']
sage: G.show(figsize=[4,4], graph_border=True)
Launched png viewer for Graphics object consisting of 11 graphics primitives
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-03-03 16:06:39 +0100

Seen: 3,908 times

Last updated: Mar 03 '16