Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Neo4j或NetworkX中有没有办法找到图形的中心?_Python_Neo4j_Networkx_Graph Theory_Graph Algorithm - Fatal编程技术网

Python 在Neo4j或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

我是图论新手。目前我正在使用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 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确实具有这样的偏心率。