simulation - 如何使用 OSMnx 和对应于图形节点的值列表在 Python 中创建热图?
问题描述
我已经使用 OSMnx 建立了一个行人在网络上行走的模拟模型,模拟的输出之一是一个列表“访问”,它对应于NodesList = list(Graph.nodes)
. 如何使用这些列表和 OSMnx 创建热图?
例如:
NodesList[:5]
Output: [1214630921, 5513510924, 5513510925, 5513510926, 5243527186]
Visits[:5]
Output: [1139, 1143, 1175, 1200, 1226]
PS 热图的类型并不重要(节点大小、节点颜色等)
解决方案
Since you specified the type of heatmap is not important, I have come up with the following solution.
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)
推荐阅读
- reactjs - 使用 jest 和 testing-library 测试组件内的函数
- apache-spark - 如何在时间段约束和其他条件下使用 Windows over 函数 PySpark
- docusaurus - 将带有状态的组件添加到 docusaurus 标头
- python - 无效语法:Django 核心中的 ImportError,e
- c# - 读取多部分/表单数据 aws lamda .NET 核心
- rest - 记录付费 REST api 功能时要考虑的事项
- python - 当两个或多个字典具有相同的键值对时合并它们
- google-apps-script - 使用 GAS 检测以前被打瞌睡的消息
- reactjs - 如何忽略 Tailwind CSS 中的链接组件?
- php - 允许创建模型内容,但在索引过滤器中仅显示 Laravel Nova 中的用户内容