开发者

Arranging the nodes in networkx in given format

开发者_StackOverflow

I have 2 list of nodes A and B for graph G in networkx.

I want to draw the nodes such that List A remains on left side and nodes in List B on right side.

For this I want to know the size of the window and do something like for nodes in List A have spring layout on the left side of window and the same for List B on right side.

Is there any way to do so.... ?

import matplotlib.pyplot as plt
import networkx as nx
g = nx.Graph()
ListA = [1]
ListB = [2]
for node in ListA:
    g.add_node(node)
for node in ListB:
    g.add_node(node)
pos=nx.spring_layout(g)   // want to change the position of all the nodes such that ListA is on left and ListB is on right
print pos
nx.draw_networkx_nodes(g,pos,nodelist=ListA,node_color='r')
nx.draw_networkx_nodes(g,pos,nodelist=ListB,node_color='g')
nx.draw_networkx_labels(g,pos)
plt.show()


This link draws the graphs seperately, but I'm not sure it draws them in any particular orientation.

http://networkx.lanl.gov/examples/drawing/atlas.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜