python - 在 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 ]
我对根据每个网格框中的密度(数据点数)对每个网格框进行颜色缩放感兴趣。
任何帮助表示赞赏。
谢谢
解决方案
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()
推荐阅读
- delphi - GetInstructionSize() BEA 引擎使用 Delphi /Lazarus
- aix - 如何检查 aix 系统是否是最新的(更新和安全修复)
- haskell - 我可以派生一个新类型的“数据”实例吗?
- r - 如何使用 tidyjson 包将 JSON 文件转换为数据框?
- mapbox - 任何熟悉散景中 mapbox 的实现的人?
- python - 使用字符串替换时如何在Python中屏蔽双引号?
- ios - 点击 scnplane 时如何将 3d 对象添加到参考图像?
- java - gmapsfx 用破折号连接两个点
- python - 使用 Qsetting 或替代方法将应用程序的状态存储在文件中
- sql-server - 使用参数化插入查询,但转换日期时转换失败