First time here? Check out the FAQ!

Ask Your Question
4

plot directed bipartite graph

asked 10 years ago

calc314 gravatar image

updated 10 years ago

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

1 Answer

Sort by » oldest newest most voted
3

answered 10 years ago

fidbc gravatar image

updated 10 years ago

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

Preview: (hide)
link

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 ( 10 years ago )

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

ppurka gravatar imageppurka ( 10 years ago )

Brilliant! Thank you both!

calc314 gravatar imagecalc314 ( 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

Stats

Asked: 10 years ago

Seen: 925 times

Last updated: Apr 12 '14