如何用罗宾逊投影绘制Cartopy pcolormesh?

问题描述 投票:0回答:1

我有一段简单的代码和卫星数据,可以按照 Cartopy 的默认投影“PlateCarree”的预期工作:

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

#get data
f = Dataset('data/matt.nc')
lats = f['lat'][:]
lons = f['lon'][:]
x = f['aot_869'][:]

#plot
ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_feature(feature.COASTLINE, edgecolor='grey')
plt.pcolormesh(lons, lats, x, transform=ccrs.PlateCarree())
plt.show()

PlateCarree projection

但是当我将投影更改为其他任何内容(包括“Robinson”)时,海岸线消失,卫星数据保留在 PlateCarree 投影中。

#plot
ax = plt.axes(projection=ccrs.Robinson())
ax.add_feature(feature.COASTLINE, edgecolor='grey')
plt.pcolormesh(lons, lats, x, transform=ccrs.Robinson())
plt.show()

Robinson projection

python matplotlib cartopy map-projections
1个回答
0
投票

由于某种原因,plt.axes 需要位于 Robinson 投影中,而 plt.pcolormesh 需要位于 PlateCarree 投影中,以使整个图形位于 Robinson 中。

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

#get data
f = Dataset('data/matt.nc')
lats = f['lat'][:]
lons = f['lon'][:]
x = f['aot_869'][:]

#plot
ax = plt.axes(projection=ccrs.Robinson())
ax.add_feature(feature.COASTLINE, edgecolor='grey')
plt.pcolormesh(lons, lats, x, transform=ccrs.PlateCarree())
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.