本文整理汇总了Python中networkx.Graph.node[node]['pos']方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.node[node]['pos']方法的具体用法?Python Graph.node[node]['pos']怎么用?Python Graph.node[node]['pos']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.Graph
的用法示例。
在下文中一共展示了Graph.node[node]['pos']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import node[node]['pos'] [as 别名]
if graph.degree(node) == 0:
orphaned.add(node)
i += 1
print('{0}/{1} nodes processed'.format(i, n), end='\r')
print('{0}/{1} nodes processed'.format(i, n))
print('Delete {0} orphaned nodes'.format(len(orphaned)))
graph.remove_nodes_from(orphaned)
print('Calculate offset')
points = [node[1]['pos'] for node in graph.nodes(data=True)]
min_x = min(points, key=lambda p: p[0])[0]
min_y = min(points, key=lambda p: p[1])[1]
for node in graph.nodes_iter():
pos = (graph.node[node]['pos'][0] - min_x, graph.node[node]['pos'][1] - min_y)
graph.node[node]['pos'] = pos
print('Translated data by ({0}, {1})'.format(-min_x, -min_y))
print('Calculate edge weights')
n = graph.number_of_edges()
i = 0
for edge in graph.edges():
lat1 = math.radians(graph.node[edge[0]]['lat'])
lon1 = math.radians(graph.node[edge[0]]['lon'])
lat2 = math.radians(graph.node[edge[1]]['lat'])
lon2 = math.radians(graph.node[edge[1]]['lon'])
graph[edge[0]][edge[1]]['weight'] = distance(lat1, lon1, lat2, lon2)
i += 1
print('{0}/{1} edges processed'.format(i, n), end='\r')
print('{0}/{1} edges processed'.format(i, n))