You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Python绘制南极洲DEM并叠加经纬度

解决南极洲DEM绘图叠加经纬度的问题

你当前代码的核心问题是:BedMachine Antarctica数据中的x和y是南极极地立体投影的平面坐标,并非经纬度值,直接用它们设置extent后,坐标轴显示的是投影坐标数值,不是经纬度。下面提供两种可行的解决方法:

方法1:将投影坐标转换为经纬度

使用pyproj库把投影坐标转成标准经纬度,再用更适合投影数据的pcolormesh绘图:

import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset
from pyproj import Transformer

# 加载数据,注意路径加r前缀避免转义错误
nc = Dataset(r"c:\Users\Admin\Desktop\PYTHON\BedMachineAntarctica-v3.nc")
x = nc.variables['x'][:]
y = nc.variables['y'][:]
# 若要绘制表面高程,可替换为srf变量,当前用的是冰厚thickness
elevations = nc.variables['thickness'][:]

# 定义投影转换:BedMachine采用EPSG:3031南极投影,转WGS84经纬度(EPSG:4326)
transformer = Transformer.from_crs("EPSG:3031", "EPSG:4326", always_xy=True)
# 生成网格坐标
xx, yy = np.meshgrid(x, y)
# 转换为经纬度
lons, lats = transformer.transform(xx, yy)

# 绘图
fig, ax = plt.subplots(figsize=(10, 8))
im = ax.pcolormesh(lons, lats, elevations, cmap='terrain', shading='auto')
ax.set_title('Antarctic Ice Surface Topography')
ax.set_xlabel('Longitude (°E)')
ax.set_ylabel('Latitude (°S)')
# 添加经纬度网格
ax.grid(True, linestyle='--', alpha=0.7)
fig.colorbar(im, ax=ax, label='Ice Thickness (m)')
plt.show()

方法2:使用Cartopy处理极地投影(推荐)

直接用Cartopy配置南极专属投影,自动生成经纬度网格,更适配极地数据可视化:

import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset
import cartopy.crs as ccrs

# 加载数据
nc = Dataset(r"c:\Users\Admin\Desktop\PYTHON\BedMachineAntarctica-v3.nc")
x = nc.variables['x'][:]
y = nc.variables['y'][:]
elevations = nc.variables['thickness'][:]

# 设置南极极地立体投影
proj = ccrs.SouthPolarStereo()

fig, ax = plt.subplots(figsize=(10, 8), subplot_kw={'projection': proj})
# 绘制数据,指定数据的投影类型
im = ax.imshow(elevations, cmap='terrain', origin='lower', 
               extent=[x.min(), x.max(), y.min(), y.max()],
               transform=proj)
# 添加海岸线(可选)
ax.coastlines()
# 添加带标签的经纬度网格
ax.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False)
ax.set_title('Antarctic Ice Surface Topography')
fig.colorbar(im, ax=ax, label='Ice Thickness (m)')
plt.show()

额外提示

  • 文件路径需加r前缀,避免\U等转义字符引发错误;
  • 若要绘制冰面高程而非冰厚,将thickness替换为变量srf即可。

内容的提问来源于stack exchange,提问作者LIKHITH GOPINATH

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 09:12:52