# Changing the text in a vertex of a graph

This is a graph

T = Graph()
E = [(0, 1), (1, 2), (1, 3),(2, 3), (2, 4)]
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 close merge delete

Sort by » oldest newest most voted

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']}

more

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

( 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))

( 2019-10-27 17:39:00 +0200 )edit