我有一个包含许多组件的图表,我想将其可视化。作为一个特殊特征,巨型组件中节点的节点点应随其特征向量中心性缩放。所有其他节点具有相同的大小。
我使用以下脚本:
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()
一切都非常正确,因为我检查了不同的输出。但是,我收到一个输出,其中除了巨型组件之外的组件中的一些节点是按比例缩放的。此外,巨型组件中的节点未正确缩放。
This snapshot shows the giant component and an off-component with a scaled node:
但是,如果我只打印巨大的组件G
使用字典eigenvector
对于节点大小,我得到以下正确的输出(:
我也做了一些故障排除。例如,字典/列表node_sizes
都是正确的。有趣的是,使用随机图H = nx.fast_gnp_random_graph(300, 0.005, seed=5)
返回正确的结果。因此我完全不知道我的有什么问题H
.