我有一段简单的代码和卫星数据,可以按照 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()
但是当我将投影更改为其他任何内容(包括“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()
由于某种原因,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()