Ask Your Question
4

plot directed bipartite graph

asked 2014-04-11 09:50:53 +0200

calc314 gravatar image

updated 2015-01-14 14:23:18 +0200

FrédéricC gravatar image

I would like to have a plot of a directed bipartite graph. I can easily get the bipartite graph to look nice or the directed graph. But, I would like a bipartite picture with the directed edges. Here is what I've tried.

G=Graph()
left=['S1','S2','S3']
rt=['T1','T2','T3','T4']
for v in left+rt:
    G.add_vertex(v)
for l in left:
    for r in rt:
        G.add_edge(l,r)
BipartiteGraph(G).to_directed().plot()
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2014-04-11 23:01:51 +0200

fidbc gravatar image

updated 2014-04-12 12:07:47 +0200

ppurka gravatar image

Just a slight modification of your code. Not sure if this is what you are looking for.

G = DiGraph() # G=Graph(); Use DiGraph instead. (-ppurka)
left=['S1','S2','S3']
rt=['T1','T2','T3','T4']
pre_pos=graphs.CompleteBipartiteGraph(len(left),len(rt)).get_pos()
pos={}
for (i,v) in enumerate(left+rt):
    G.add_vertex(v)
    pos[v]=pre_pos[i]
for l in left:
    for r in rt:
        G.add_edge(l,r)
G.plot(pos=pos) # G.to_directed().plot(pos=pos); Graph is already directed (-ppurka)

Sample output (new sample output -ppurka): image description

edit flag offensive delete link more

Comments

This is close to what I was aiming for. Thank you! Is there a way to only have edges coming out of the S vertices and going into the T vertices?

calc314 gravatar imagecalc314 ( 2014-04-12 08:58:03 +0200 )edit

Updated the first and last line of @fidbc's code. Nice idea there, fidbc.

ppurka gravatar imageppurka ( 2014-04-12 12:08:21 +0200 )edit

Brilliant! Thank you both!

calc314 gravatar imagecalc314 ( 2014-04-12 14:49:08 +0200 )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

Stats

Asked: 2014-04-11 09:50:53 +0200

Seen: 790 times

Last updated: Apr 12 '14