Ask Your Question

# plot directed bipartite graph 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 close merge delete

## 1 Answer

Sort by » oldest newest most voted 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): 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?

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

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

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

Seen: 499 times

Last updated: Apr 12 '14