Ask Your Question
0

Changing the text in a vertex of a graph

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

Cyrille gravatar image

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

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 09:31:57 +0100

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 10:17:50 +0100 )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 +0100 )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 09:12:17 +0100

Seen: 469 times

Last updated: Oct 27 '19