问题描述
|
我在networkx中有2个图G的节点A和B的列表。
我想绘制节点,使列表A保留在左侧,而列表B的节点保留在右侧。
为此,我想知道窗口的大小,并为列表A中的节点执行类似的操作,在窗口的左侧具有弹簧布局,对于列表B的右侧具有相同的弹簧布局。
有什么办法可以做到...?
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,nodelist=ListB,node_color=\'g\')
nx.draw_networkx_labels(g,pos)
plt.show()
解决方法
此链接分别绘制图形,但我不确定它是否以任何特定方向绘制图形。
http://networkx.lanl.gov/examples/drawing/atlas.html