Ask Your Question

Changing the text in a vertex of a graph

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

Cyrille gravatar image

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

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 03:31:57 -0500

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 04:17:50 -0500 )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 -0500 )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 03:12:17 -0500

Seen: 62 times

Last updated: Oct 27 '19