python中地理空间数据的分块和打印

2024-04-27 04:59:09 发布

您现在位置: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 ]

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

感谢您的帮助

谢谢

gridded binned data


Tags: 数据网格数量颜色可视化空间数组variable
1条回答
网友
1楼 · 发布于 2024-04-27 04:59:09

当使用numpy矩阵时,绘图将如下所示。请注意,对于本例,点仅为6。然后可以使用matplotlib语法进行修改

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

相关问题 更多 >