【问题标题】:Binning and plotting geospatial data in python在 python 中分箱和绘制地理空间数据
【发布时间】:2020-01-09 12:05:43
【问题描述】:

我是 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

【问题讨论】:

  • 我会这样做。用 numpy 制作网格矩阵并计算每个网格单元有多少数据。然后绘制heatmap with matplotlib.
  • 感谢 Shimo,我应该提到我的 lats/lons 数据不是单调的,即。无序(值上升和下降)并且还有重复值,因为这些是感兴趣变量的卫星跟踪数据。我真正想要的是在附加(网格分箱数据)图像中看到的地图
  • 我想我正在遵循您想要的结果。请尝试回答示例。

标签: python mapping geospatial


【解决方案1】:

当使用 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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-11
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多