英文:
How to draw a heatmap with grids of different colors in a map?
问题
[Fig.1]:https://i.stack.imgur.com/YUbeF.png
感谢您事先的时间和专业知识。
最好的问候
英文:
Recently I have been reading a paper called Modeling Taxi Drivers’ Behaviour for the Next Destination Prediction. There is a figure(Fig.1) that I wonder how to draw. Based on what I know, it may be drawn by Python. Then what library of Python should I use to draw such a heatmap?
Thanks a lot in advance for your time and your expertise.
Best Regards
答案1
得分: 0
-
构建网格:
地图上的网格是纬度和经度的X大小
的正方形。简而言之,这些是纬度和经度网格。我使用了一个名为leaflet.js
的交互式地图库来在世界地图上叠加纬度和经度网格。这是我遵循的leaflet教程链接: https://leafletjs.com/examples/choropleth/
请记住,您可以按照教程中讨论的使用GeoJSON
构建网格的方式来创建自己的版本,并叠加到世界地图上。至少在我构建时,还没有公开可用的纬度/经度正方形网格版本。 -
显示颜色(热力图):
一旦您使用GeoJSON构建了网格,leaflet可以将整个GeoJSON作为它本来的形式叠加到您选择的任何地图上。这意味着您可以将每个网格的数字(也称为数据)放入GeoJSON中。这一部分也在同一教程中展示。
对于我的项目,我习惯于在Python
中创建一个完整的GeoJSON
格式文件,其中包含规范化的数据,然后在leaflet.js
中可视化它。下面是我使用这些工具构建的示例。
英文:
I have built something very similar for myself in the past. However, as you are just wondering how this would be drawn and not exactly asking how to do it with Python, I will share how I did it.
1. Building Grid:
The grids on the map are squares of X-size
latitude and longitude. In short, those are latitude and longitude grids. I used an interactive map library named leaflet.js
to build the world map with an overlay of latitude and longitude grids. This is the tutorial I followed from the leaflet: https://leafletjs.com/examples/choropleth/
Remember, you have to and can build your version of the grid to overlay on a world map using GeoJSON
as discussed in the tutorial. At least, when I was building, there wasn't a publicly available version of the lat/long square grid.
2. Showing Colors (Heatmap):
Once you build the grid with GeoJSON, the leaflet can take the whole GeoJSON as it is and overlay it on any map of your choice. That means you can put the numbers(aka data) for each grid in the GeoJSON. This part is also shown in the same tutorial.
For my project, I used to create a complete GeoJSON
formatted file with normalized data in Python
and then visualize it in leaflet.js
. Below is an example of what I have built using these tools.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论