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

Python中无法正确绘制.netCDF海冰数据(Basemap、Cartopy)

解决EPSG:3411海冰浓度数据的绘图异常问题

问题根源

你的代码存在两个核心错误:

  • Cartopy部分:将米单位的投影坐标(EPSG:3411)误当作经纬度(PlateCarree)处理,且未指定数据的正确投影。
  • Basemap部分:EPSG:3411的中央经线为-45°而非0°,参数不匹配导致投影错位。

修正后的Cartopy实现

import xarray as xr
import cartopy.crs as ccrs 
import matplotlib.pyplot as plt

data = xr.open_dataset('df.nc')
sea_ice = data.F17_ICECON

# 定义EPSG:3411对应的北极立体投影
data_crs = ccrs.NorthPolarStereo(central_longitude=-45, true_scale_latitude=70)
# 使用数据投影作为绘图投影(也可改用其他投影如PlateCarree)
ax = plt.axes(projection=data_crs)

# 绘制时指定数据的坐标系,Cartopy会自动完成转换
ax.contourf(data.x, data.y, sea_ice[4], transform=data_crs)

ax.coastlines()
ax.gridlines(draw_labels=True)
plt.show()

修正后的Basemap实现

import xarray as xr
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np

data = xr.open_dataset('df.nc')
sea_ice = data.F17_ICECON

# 严格匹配EPSG:3411的投影参数
m = Basemap(width=6000000, height=6000000,
            resolution='l', projection='stere',
            lat_0=90, lon_0=-45, epsg=3411)

x, y = np.meshgrid(data.x, data.y)
m.pcolormesh(x, y, sea_ice[2])
m.drawcoastlines()
m.fillcontinents(color='grey')
m.drawparallels(np.arange(60., 91., 10.))
m.drawmeridians(np.arange(-180., 181., 30.))

plt.show()

关键提示

EPSG:3411是WGS84北极海冰极立体投影,必须使用central_longitude=-45°、true_scale_latitude=70°这两个核心参数,才能保证投影对齐。绘图时需明确告知工具:数据坐标属于EPSG:3411,而非默认的经纬度坐标系。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 22:43:13