为太平洋设置 cartopy set_extent(160E ~ -90W 或 160 ~ 270)不起作用

setting cartopy set_extent for pacific ocean (160E ~ -90W or 160 ~ 270) not working

我正在尝试仅在热带太平洋地区投影地图,范围从 160E 到 -90W(或 160 到 270),如下例

paco_region    =  plt.axes(projection=ccrs.PlateCarree())
paco_region.coastlines()
paco_region.set_extent([160,-90,-20,20],crs=ccrs.PlateCarree())
paco_region.gridlines(crs=ccrs.PlateCarree(), draw_labels=True)

plt.show()

问题是 cartopy 拒绝显示从 160E(设置为左边界)到 -90W(设置为右边界)的地图。只显示了从-90W到160W的映射(如下图)

我该如何解决这个问题?

你需要一些坐标变换和一些小技巧来完成它。

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

# define CRS's for our use case
crs0 = ccrs.PlateCarree(central_longitude=0)     #for coding data, same as ccrs.PlateCarree()
crs180 = ccrs.PlateCarree(central_longitude=180) #for plotting map in pacific area

# For all plotting, use `crs180`
fig, paco_region = plt.subplots(figsize=(9,5), subplot_kw={'projection': crs180})

#paco_region.stock_img()  # background image check-plot
paco_region.coastlines()

paco_region.set_extent([160, 270, -20, 20], crs=crs0)

# Sample plot of users' data
# Just use regular long/lat
lons = [175, 185, 195, 220, 250]
lats = [15, 0, -15, 12, 18]
# ... but specify `transform = crs0` when plot the data.
paco_region.scatter(lons, lats, transform=crs0, color="r")

# For grid-line labelling, use `crs0`
paco_region.gridlines(crs=crs0, draw_labels=True)

plt.show()