我有許多想要形象化的組件的圖。作爲一個特殊的特徵,巨組件中節點的節點應按照它們的特徵向量中心性進行縮放。所有其他節點具有相同的大小。使用多個組件繪製圖形時節點大小不正確
我使用下面的腳本:
import networkx as nx
import pylab as py
import matplotlib.pyplot as plt
H = nx.read_gexf(input_file)
print nx.info(H)
#Name:
#Type: Graph
#Number of nodes: 719
#Number of edges: 620
#Average degree: 1.7246
# Set draw() parameters
node_sizes = dict.fromkeys(H.nodes(), 0.005)
# Make node size of giant component nodes proportional to their eigenvector
eigenvector = nx.eigenvector_centrality_numpy(G)
for node, value in eigenvector.iteritems():
node_sizes[node] = round(value, 4)
node_sizes = [v*2000 for v in node_sizes.values()] # rescale
node_positions = nx.pygraphviz_layout(H, prog="neato")
# Draw graph with different color for each connected subgraph
plt.figure(3, figsize=(90,90))
nx.draw(H, font_size=10, pos=node_positions, node_size=node_sizes, vmin=0.0, vmax=1.0, with_labels=True)
plt.show()
一切都是非常正確,我在不同輸出檢查。但是,我收到一個輸出,其中來自巨型組件以外的組件的一些節點是可擴展的。此外,巨型組件中的節點未正確縮放。
該快照顯示了巨大的分量和關閉組件與縮放節點:
但是,如果我只使用字典eigenvector
的節點尺寸打印的巨組G
,我得到如下 - 正確 - 輸出(:
我做了一些故障排除,太例如,詞典/名單node_sizes
是正確有趣的是,採用了隨機圖。返回正確的結果。所以我完全不知道我的H
有什麼問題。
- 但因爲我沒有你輸入網絡沒有測試它。請檢查它並讓我知道 - 特別是如果它不起作用。 – Joel 2015-04-03 20:32:38