以给定格式排列 networkx 中的节点
我在 networkx 中的图 G 有 2 个节点 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,pos,nodelist=ListB,node_color='g')
nx.draw_networkx_labels(g,pos)
plt.show()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此链接单独绘制图表,但我不确定它是否以任何特定方向绘制它们。
http://networkx.lanl.gov/examples/drawing/atlas.html
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