有人能帮忙吗。我正在获取一个网络并将其绘制为如下图:
g = nx.DiGraph()
//creating the graph......
print(nx.info(g))
nx.info(g) 给我的节点数是 18772。
我得到了它的图表如下:
然而,在删除 30% 的最重要节点后,如下所示:
thirty_percent = int(g.number_of_nodes() * 0.30)
temp_g = g.copy()
print('initial number of nodes:', g.number_of_nodes())
print('nodes deleted (30%):', thirty_percent)
mostImportantNodes = sorted(nx.degree_centrality(g).items(), key=lambda x: x[1], reverse=True)
for n in range(0, thirty_percent):
node = mostImportantNodes[n][0]
temp_g.remove_node(node)
print(nx.info(temp_g))
# drawing the network graph
print('Graph after removing 30% of the most important nodes:')
print(datetime.now())
plt.clf()
pos = nx.spring_layout(temp_g)
nx.draw_networkx_nodes(temp_g, pos, node_size=10)
nx.draw_networkx_edges(temp_g, pos, edge_color='black', alpha=0.1, arrows=True)
plt.show()
print(datetime.now())
它提供了有关新图表的正确信息,但图表非常糟糕,似乎节点是添加而不是删除!
initial number of nodes: 18772
nodes deleted (30%): 5631
Name:
Type: DiGraph
Number of nodes: 13141
Number of edges: 44911
Average in degree: 3.4176
Average out degree: 3.4176
highest 5 degrees: [40, 40, 38, 36, 36]