Ask Your Question

Changing the text in a vertex of a graph

asked 2019-10-27 09:12:17 +0200

Cyrille gravatar image

updated 2019-10-27 09:55:23 +0200

FrédéricC gravatar image

This is a graph

T = Graph()
E = [(0, 1), (1, 2), (1, 3),(2, 3), (2, 4)]

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

answered 2019-10-27 09:31:57 +0200

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


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 10:17:50 +0200 )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 17:39:00 +0200 )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


Asked: 2019-10-27 09:12:17 +0200

Seen: 96 times

Last updated: Oct 27 '19