Python 在Neo4j或NetworkX中有没有办法找到图形的中心?
我是图论新手。目前我正在使用Neo4j,我需要在子图中找到中心节点进行分析。有没有办法在Neo4j或NetworkX中找到中心节点 这可以在NetworkX中使用来完成,它返回图形中的中心节点列表。下面是以红色绘制中心节点的示例 示例代码:Python 在Neo4j或NetworkX中有没有办法找到图形的中心?,python,neo4j,networkx,graph-theory,graph-algorithm,Python,Neo4j,Networkx,Graph Theory,Graph Algorithm,我是图论新手。目前我正在使用Neo4j,我需要在子图中找到中心节点进行分析。有没有办法在Neo4j或NetworkX中找到中心节点 这可以在NetworkX中使用来完成,它返回图形中的中心节点列表。下面是以红色绘制中心节点的示例 示例代码: import networkx as nx from networkx.algorithms.distance_measures import center # Set up graph G = nx.barbell_graph(5, 5) # Get
import networkx as nx
from networkx.algorithms.distance_measures import center
# Set up graph
G = nx.barbell_graph(5, 5)
# Get position using spring layout
pos = nx.spring_layout(G)
# Get center node(s)
c = center(G)
# Draw non-central nodes & all edges
nx.draw_networkx_nodes(G, pos, nodelist=set(G.nodes)-set(c))
nx.draw_networkx_edges(G, pos)
# Draw central nodes in red
nx.draw_networkx_nodes(G, pos, nodelist=c, node_color='r')
# Draw labels
nx.draw_networkx_labels(G, pos)
G = nx.barbell_graph(5, 5)
输出:
import networkx as nx
from networkx.algorithms.distance_measures import center
# Set up graph
G = nx.barbell_graph(5, 5)
# Get position using spring layout
pos = nx.spring_layout(G)
# Get center node(s)
c = center(G)
# Draw non-central nodes & all edges
nx.draw_networkx_nodes(G, pos, nodelist=set(G.nodes)-set(c))
nx.draw_networkx_edges(G, pos)
# Draw central nodes in red
nx.draw_networkx_nodes(G, pos, nodelist=c, node_color='r')
# Draw labels
nx.draw_networkx_labels(G, pos)
G = nx.barbell_graph(5, 5)
什么是中心节点?这里的中心节点是指偏心率等于半径的节点。显然,networkx确实具有这样的偏心率。