首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >OSMnx教程8(波音)-中心

OSMnx教程8(波音)-中心
EN

Stack Overflow用户
提问于 2019-03-25 03:15:08
回答 1查看 534关注 0票数 0

我有两个部分的问题,与波音的OSMnx教程8街网络中心性分析。首先,我有一个关于边缘封闭中心性的知识问题,然后是一个关于边缘间中心性的基于代码的问题。我的目的是计算边缘贴近度和中间中心在不同的地点站周围。

1.边缘封闭中心性

下面的代码对我很有用:

代码语言:javascript
运行
复制
# edge closeness centrality: convert graph to a line graph so edges become nodes and vice versa
edge_centrality = nx.closeness_centrality(nx.line_graph(G))

# list of edge values for the original graph
ev = [edge_centrality[edge + (0,)] for edge in G.edges()]

# color scale converted to list of colors for graph edges
norm = colors.Normalize(vmin=min(ev)*0.8, vmax=max(ev))
cmap = cm.ScalarMappable(norm=norm, cmap=cm.inferno)
ec = [cmap.to_rgba(cl) for cl in ev]

问:有人能解释为什么在标准化代码中,最小边缘值乘以0.8,最大值设置为最大边缘值吗?我对文献不太熟悉,所以如果有任何建议,我将不胜感激。

2.边缘之间的中心性

我试图用类似于上面代码的方法计算边之间的中心性,以表示在示例中同一图上的边贴近中心性。我尝试过这样做,得到了以下信息:

代码语言:javascript
运行
复制
# edge betweenness centrality
edge_bcentrality = nx.edge_betweenness_centrality(G)

# list of edge values for the orginal graph
ev1 = [edge_bcentrality[edge + (0,)] for edge in G.edges()]

# color scale converted to list of colors for graph edges
norm = colors.Normalize(vmin=min(ev1)*0.8, vmax=max(ev1))
cmap = cm.ScalarMappable(norm=norm, cmap=cm.inferno)
ec = [cmap.to_rgba(cl) for cl in ev1]

# color the edges in the original graph with betweeness centralities in the line graph
fig, ax = ox.plot_graph(G, bgcolor='k', axis_off=True, node_size=0, node_color='w', node_edgecolor='gray', node_zorder=2,
                        edge_color=ec, edge_linewidth=1.5, edge_alpha=1)

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-14-6ee1d322067c> in <module>()
      1 # list of edge values for the orginal graph
----> 2 ev1 = [edge_bcentrality[edge + (0,)] for edge in G.edges()]
      3 
      4 # color scale converted to list of colors for graph edges
      5 norm = colors.Normalize(vmin=min(ev)*0.8, vmax=max(ev))

KeyError: (53090322, 53082634, 0)

如果有人建议最好的方法来计算边缘之间的中心性,我会非常感激,因为我仍然是一个新手。此外,如果有人能分享进行正常化的最佳方式,我们将不胜感激。

谢谢您抽时间见我,

BC

EN

回答 1

Stack Overflow用户

发布于 2019-11-16 21:40:54

我应用了这段代码,它适用于我。希望能帮上忙。

代码语言:javascript
运行
复制
#calculate betweenness
betweenness = nx.edge_betweenness(G=G, normalized=False)

# iterate over edges
edges = []
for i in betweenness.items():
    i = i[0] + (0,)
    edges.append(i)
for i,j in zip(edges,betweenness.keys()): 
    betweenness[i] = betweenness[j]
    del betweenness[j]

# color scale converted to list of colors for graph edges
norm = colors.Normalize(vmin=min(betweenness.values())*0.8, vmax=max(betweenness.values()))
cmap = cm.ScalarMappable(norm=norm, cmap=cm.viridis)
ec = [cmap.to_rgba(cl) for cl in betweenness.values()]

# color the edges in the original graph with betweeness centralities in the line graph
fig, ax = ox.plot_graph(G, bgcolor='w', axis_off=True, node_size=0, node_color='w', node_edgecolor='gray', node_zorder=2,
                        edge_color=ec, edge_linewidth=1.5, edge_alpha=1)
fig.show()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55330838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档