如何在Jupyter Noteb中表示地理地图上的标量变量

2024-05-29 11:32:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Jupyter笔记本中表示一些地理数据:温度、海浪高度等。我有numpy数组,其中包含纬度、经度和这些变量的值。我想在地理地图上显示这些变量,最好使用ipyleaflet(因为这是我已经在使用的)。我试图得到一个类似于热图的结果。你知道吗

我试着使用ipyleaflet热图,但在我看来,它是用来表示一个点的着色,而不是标量均匀的数组,因为我不能让它正确地显示结果。我认为ipyleaflet可能缺少一个函数来表示这类数据,但似乎很奇怪,因为它有一个非常好的速度函数来表示向量变量。你知道吗

我能想到的唯一方法是用matplotlib生成一个图像,然后将其添加到图像层的地图中,但我觉得这不是正确的方法。你知道吗


Tags: 数据方法函数图像numpy高度地图笔记本
4条回答

为了表示热图,我建议将Cartopy与Matplotlib结合使用。 下面是我为一个有海岸线的世界投影制作的现成脚本:

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.util import add_cyclic_point


# Set x y z variables
x = longitude_data
y = latitude_data
z = heat_map_data

# Set up figure and projection
z, x = add_cyclic_point(z, coord=x) 
fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection=ccrs.PlateCarree() )

# Set data range and colourmap
levels = np.arange(min,max,steps) 
plt.contourf(x, y, z,levels = levels,transform=ccrs.PlateCarree(),cmap="rainbow")

# Set axes, extent (world) and labels 
ax.set_xticks(np.linspace(-180,180,num=7), crs=ccrs.PlateCarree()) 
ax.set_yticks(np.linspace(-60,60,num=5), crs=ccrs.PlateCarree())
ax.add_feature(cfeature.COASTLINE) #Add coastline
ax.set_global()
ax.set_title('Heatmap')
ax.set_xlabel('Longitude')
ax.set_ylabel('Latitude')

# Add colorbar 
plt.colorbar(ax=ax,shrink=0.7,orientation="vertical")

fig.show()

使用Cartopy和Matplotlib文档,您现在应该可以创建一些地图了。你知道吗

相关问题 更多 >

    热门问题