首页 > 解决方案 > 在 python 中分箱和绘制地理空间数据

问题描述

我是 python 中数据地理空间映射的新手,我想将我的数据可视化为 1 x 1 度网格。我的数据在 3 个单独的数组中,例如

variable_lats: [ 20.099339 20.142488 20.101004 ... -38.988274 -38.988274 -38.9924 ]

variable_lons: [280.017 279.97015 280.03192 ... 22.829168 22.829168 22.834965]

variable_values: [ 6.388523 6.317164 6.3859496 ... 20.035767 19.707344 19.379091 ]

我对根据每个网格框中的密度(数据点数)对每个网格框进行颜色缩放感兴趣。

任何帮助表示赞赏。

谢谢

网格分箱数据

标签: pythonmappinggeospatial

解决方案


When used numpy matrix, plot will be like this. Note that points are only 6 for this example. Then you can modify with matplotlib syntax.

import numpy as np
from matplotlib import pyplot as plt

# matrix which have 1x1 degree
# matrix_denx[0][0] is count of area lat 89 to 90, long 0 to 1
matrix_dens = np.zeros((180, 360))

variable_lats = [20.099339, 20.142488, 20.101004, -38.988274, -38.988274, -38.9924]

variable_lons = [280.017, 279.97015, 280.03192, 22.829168, 22.829168, 22.834965]

for x, y in zip(variable_lons, variable_lats):

    x_ind = int(np.floor(x))
    y_ind = int(90 - np.floor(y))

    # set value for x_ind, y_ind. += 1 for count.
    matrix_dens[y_ind][x_ind] += 1

# heatmap
fig, ax = plt.subplots()
im = ax.imshow(matrix_dens, cmap="YlGnBu")
plt.show()

enter image description here


推荐阅读