Ask Your Question
4

plot directed bipartite graph

asked 2014-04-11 02:50:53 -0500

calc314 gravatar image

updated 2015-01-14 07:23:18 -0500

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 16:01:51 -0500

fidbc gravatar image

updated 2014-04-12 05:07:47 -0500

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 01:58:03 -0500 )edit

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

ppurka gravatar imageppurka ( 2014-04-12 05:08:21 -0500 )edit

Brilliant! Thank you both!

calc314 gravatar imagecalc314 ( 2014-04-12 07:49:08 -0500 )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 02:50:53 -0500

Seen: 270 times

Last updated: Apr 12 '14