我从Matlab获得了环网的边缘列表。然后,NetworkX读取此列表并以圆形布局绘制图形。我的边缘列表如下:
['1,2', '1,3', '1,49', '1,50', '2,3', '2,4', '2,50', '3,4', '3,5', '4,5', '4,6', '5,6', '5,7', '6,7', '6,8', '7,8', '7,9', '8,9', '8,10', '9,10', '9,11', '10,11', '10,12', '11,12', '11,13', '12,13', '12,14', '13,14', '13,15', '14,15', '14,16', '15,16', '15,17', '16,17', '16,18', '17,18', '17,19', '18,19', '18,20', '19,20', '19,21', '20,21', '20,22', '21,22', '21,23', '22,23', '22,24', '23,24', '23,25', '24,25', '24,26', '25,26', '25,27', '26,27', '26,28', '27,28', '27,29', '28,29', '28,30', '29,30', '29,31', '30,31', '30,32', '31,32', '31,33', '32,33', '32,34', '33,34', '33,35', '34,35', '34,36', '35,36', '35,37', '36,37', '36,38', '37,38', '37,39', '38,39', '38,40', '39,40', '39,41', '40,41', '40,42', '41,42', '41,43', '42,43', '42,44', '43,44', '43,45', '44,45', '44,46', '45,46', '45,47', '46,47', '46,48', '47,48', '47,49', '48,49', '48,50', '49,50']
请注意,有些对是'1,50','2,50'等等,而其他对是递增顺序,'1,2','1,3','4,5 ' 等等。虽然构建图形不是问题,但是当我以圆形布局绘制它时,我得到了这个:
https://docs.djangoproject.com/en/1.10/intro/tutorial03/
在右侧,圆圈以第48个节点结束,该节点应该以第50个节点结束以保持视觉一致性。我怀疑的原因是有序对'1,50','2,50'等。这是绘图功能的基础还是我可以做些什么,除了手动更改我的有序对?用于绘图的说明是:
f = open('Adj1.txt', 'r')
read_data = f.read()
f.close()
edge_list = read_data.split(sep='\n')
edge_list = edge_list[1:len(edge_list)-1]
H = nx.parse_edgelist(edge_list,delimiter=',')
....
nx.draw_circular(H,with_labels=False, node_size=25, node_color=node_color)
答案 0 :(得分:1)
因为您的图表是一个简单的无向图,所以重要的不是订单(u,v)
,而是边列表的顺序。显然networkx
根据edge_list
中提及的顺序布置顶点(这在某种程度上是有意义的)
问题可以证明如下:如果网络节点50
出现在列表的早期:
import networkx as nx
edge_list=['1,2', '1,3', '1,49', '1,50', '2,3', '2,4', '2,50', '3,4', '3,5', '4,5', '4,6', '5,6', '5,7', '6,7', '6,8', '7,8', '7,9', '8,9', '8,10', '9,10', '9,11', '10,11', '10,12', '11,12', '11,13', '12,13', '12,14', '13,14', '13,15', '14,15', '14,16', '15,16', '15,17', '16,17', '16,18', '17,18', '17,19', '18,19', '18,20', '19,20', '19,21', '20,21', '20,22', '21,22', '21,23', '22,23', '22,24', '23,24', '23,25', '24,25', '24,26', '25,26', '25,27', '26,27', '26,28', '27,28', '27,29', '28,29', '28,30', '29,30', '29,31', '30,31', '30,32', '31,32', '31,33', '32,33', '32,34', '33,34', '33,35', '34,35', '34,36', '35,36', '35,37', '36,37', '36,38', '37,38', '37,39', '38,39', '38,40', '39,40', '39,41', '40,41', '40,42', '41,42', '41,43', '42,43', '42,44', '43,44', '43,45', '44,45', '44,46', '45,46', '45,47', '46,47', '46,48', '47,48', '47,49', '48,49', '48,50', '49,50']
H = nx.parse_edgelist(edge_list,delimiter=',')
nx.draw_circular(H,with_labels=False, node_size=25)
networkx
挣扎。但是,当我们将1,50
和consorts放在列表的末尾(它们属于的地方!)时,它会很好地绘制。
edge_list=['1,2', '1,3', '2,3', '2,4', '3,4', '3,5', '4,5', '4,6', '5,6', '5,7', '6,7', '6,8', '7,8', '7,9', '8,9', '8,10', '9,10', '9,11', '10,11', '10,12', '11,12', '11,13', '12,13', '12,14', '13,14', '13,15', '14,15', '14,16', '15,16', '15,17', '16,17', '16,18', '17,18', '17,19', '18,19', '18,20', '19,20', '19,21', '20,21', '20,22', '21,22', '21,23', '22,23', '22,24', '23,24', '23,25', '24,25', '24,26', '25,26', '25,27', '26,27', '26,28', '27,28', '27,29', '28,29', '28,30', '29,30', '29,31', '30,31', '30,32', '31,32', '31,33', '32,33', '32,34', '33,34', '33,35', '34,35', '34,36', '35,36', '35,37', '36,37', '36,38', '37,38', '37,39', '38,39', '38,40', '39,40', '39,41', '40,41', '40,42', '41,42', '41,43', '42,43', '42,44', '43,44', '43,45', '44,45', '44,46', '45,46', '45,47', '46,47', '46,48', '47,48', '47,49', '48,49', '48,50', '49,50','1,49', '1,50','2,50',]
H = nx.parse_edgelist(edge_list,delimiter=',')
nx.draw_circular(H,with_labels=False, node_size=25)
如果您的图表定向,则(u,v)
与(v,u)
的订单当然很重要。