Ask Your Question
1

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

asked 10 years ago

anonymous user

Anonymous

updated 10 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 10 years ago

tmonteil gravatar image

updated 10 years ago

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)
Preview: (hide)
link

Comments

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

Semin gravatar imageSemin ( 10 years ago )

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: 10 years ago

Seen: 967 times

Last updated: Jan 03 '15