Ask Your Question
0

Changing the text in a vertex of a graph

asked 2019-10-27 03:12:17 -0600

Cyrille gravatar image

updated 2019-10-27 03:55:23 -0600

FrédéricC gravatar image

This is a graph

T = Graph()
E = [(0, 1), (1, 2), (1, 3),(2, 3), (2, 4)]
T.add_edges(E)
T.set_embedding({0:[1],1:[0,3,2],2:[1,3,4],3:[1,2],4:[2]})
T.show()

I would like to know if it is possible to replace the name of the node by a text a photo ... Also how to label vertices ?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2019-10-27 03:31:57 -0600

You can relabel the vertices using any hashable type

sage: T.relabel(perm={0: 'text a', 1: 'text b', 2: 'text c', 3: 'text d', 4: ('text e', 4)})
sage: T.edges()
[('text a', 'text b', None),
 ('text b', 'text c', None),
 ('text b', 'text d', None),
 ('text c', 'text d', None),
 ('text c', ('text e', 4), None)]
sage: T._embedding
{'text a': ['text b'],
 'text b': ['text a', 'text d', 'text c'],
 'text c': ['text b', 'text d', ('text e', 4)],
 'text d': ['text b', 'text c'],
 ('text e', 4): ['text c']}
edit flag offensive delete link more

Comments

Thanks David, but there is a drawback. The size of the node is not increased, so the result is not perfectly readable.

Cyrille gravatar imageCyrille ( 2019-10-27 04:17:50 -0600 )edit

An alternative is to use latex. The size of the vertices is adjusted to surround the text.

sage: view(latex(T))
David Coudert gravatar imageDavid Coudert ( 2019-10-27 11:39:00 -0600 )edit

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: 2019-10-27 03:12:17 -0600

Seen: 72 times

Last updated: Oct 27 '19