Ask Your Question
1

Can I draw a graph whose vertices have two kind of labels?

asked 2015-01-02 14:14:14 +0100

anonymous user

Anonymous

updated 2015-01-02 14:14:54 +0100

Hello.

I want to draw a graph.

Each vertex connects to another information.

For example,

G=graphs.EmptyGraph()
G.add_vertices([1,2,3,4])
for i in [1,2,3]:
    for j in [i+1..4]:
       if j%i==0:
           G.add_edge([i,j])

V=[]
for i in G.vertices():
    if i<3:
         V=V+["Dog"]
    else:
         V=V+["Cat"]

Then 1,2 --> Dog and 3,4 --> Cat.

I want to get a plotting graph which shows the second information Dog and Cat.

Is that possible?

Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-01-03 08:57:32 +0100

tmonteil gravatar image

updated 2015-01-03 09:04:21 +0100

Unfortunately, there is no way to define non-injective labeling for vertices of Sage graphs as there is a confusion between the vertices themselves and possible labels on them, see the documentation.

For example:

sage: G.relabel(V)
NotImplementedError: Non injective relabeling

There are two possible workarounds. You can make the pseudo-labelling injective as follows:

sage: G.relabel(list(enumerate(V)))
sage: G.vertices()
[(0, 'Dog'), (1, 'Dog'), (2, 'Cat'), (3, 'Cat')]
sage: G.plot()

You can also use colors during the plot to pseudo-label the vertices:

sage: G.plot(partition=[[1,2],[3,4]])
sage: G.plot(partition=[[1,2],[3,4]], vertex_labels=False)
edit flag offensive delete link more

Comments

Thanks for nice advise~ That is very helpful for me. :)

Semin gravatar imageSemin ( 2015-01-04 05:12:48 +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: 2015-01-02 14:14:14 +0100

Seen: 942 times

Last updated: Jan 03 '15