2017-02-24 44 views
2

我從Matlab獲取我的環形網絡列表。 NetworkX然後讀取此列表並以圓形佈局繪製圖形。我邊列表的樣子:當在NetworkX中顯示圖形時,邊緣對順序(u,v)vs(v,u)是否重要?

['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'等。雖然構造圖是沒有問題的,但是當我在一個圓形佈局繪製它,我得到這個:

​​

在右手邊,圓與第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) 

回答

1

因爲你的圖是一個簡單的無向圖,它不是重要的順序(u,v),但你的優勢列表的順序。

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) 

Bad:如果網絡節點50在列表中最早出現:顯然networkx根據提及的在edge_list的順序(這使得在某種程度上意義上) 該問題可以如下來證明佈局的頂點

networkx掙扎。但是,當我們將1,50和配偶放在列表的最後(它們屬於它!)時,它會很好地繪製出來。

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) 

Good

順序(u,v) VS (v,u)做的事當然如果您的圖形是執導

+0

感謝您的清除!這意味着我必須更改我的matlab腳本以生成邊界列表的正確(必需)順序。 –

+0

很高興提供幫助。你可能比我更清楚。爲圖找到理想佈局的問題並不是微不足道的(對於某些理想的定義)是正確的? –

+0

當你有節點屬性綁定時,這當然不是微不足道的!這是原因,我有時更喜歡爲特定佈局構建我自己的小腳本。當然,他們看起來並不「專業」......但很好地服務於這個目的。 –

相關問題