gpt4 book ai didi

simulation - 如何使用 OSMnx 和与图节点对应的值列表在 Python 中创建热图?

转载 作者:行者123 更新时间:2023-12-04 17:37:33 26 4
gpt4 key购买 nike

我已经使用 OSMnx 构建了一个行人在网络上行走的仿真模型,其中一个仿真输出是与 NodesList = list(Graph.nodes) 中的节点相对应的列表“Visits”。 .
如何使用这些列表和 OSMnx 创建热图?

例如:

NodesList[:5]
Output: [1214630921, 5513510924, 5513510925, 5513510926, 5243527186]

Visits[:5]
Output: [1139, 1143, 1175, 1200, 1226]

附言
热图的类型并不重要(节点大小、节点颜色等)

最佳答案

由于您指定的热图类型并不重要,因此我提出了以下解决方案。

import osmnx as ox
address_name='Melbourne'

#Import graph
G=ox.graph_from_address(address_name, distance=300)

#Make geodataframes from graph data
nodes, edges = ox.graph_to_gdfs(G, nodes=True, edges=True)

import numpy as np
#Create a new column in the nodes geodataframe with number of visits
#I have filled it up with random integers
nodes['visits'] = np.random.randint(0,1000, size=len(nodes))

#Now make the same graph, but this time from the geodataframes
#This will help retain the 'visits' columns
G = ox.save_load.gdfs_to_graph(nodes, edges)

#Then plot a graph where node size and node color are related to the number of visits
nc = ox.plot.get_node_colors_by_attr(G,'visits',num_bins = 5)
ox.plot_graph(G,fig_height=8,fig_width=8,node_size=nodes['visits'], node_color=nc)

enter image description here

关于simulation - 如何使用 OSMnx 和与图节点对应的值列表在 Python 中创建热图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56100316/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com