add_cyclic_point
全球の描画で,極投影系の地図投影および経度の始まりが図の端に来ない場合に,経度の始まり・終わりの場所で,図に切れ目が入ってしまう.これを防ぐには,cartopy.util.dd_cyclic_pointで,経度方向にもう一点,格子点を加える.
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.util as cutil
import xarray as xr
import numpy as np
from matplotlib import pyplot as plt
lons1d=np.arange(-179.5,180,1.0)
lats1d=np.arange(-89.5,90,1.0)
xsz=len(lons1d)
ysz=len(lats1d)
lons2d=np.ones([ysz,1]) @ lons1d.reshape(1,xsz)
lats2d=lats1d.reshape(ysz,1) @ np.ones([1,xsz])
vals=lats2d*np.cos(lons2d/360*2*np.pi)
plt.ion()
lon_fig_mid=240
plt.figure(1)
ax1=plt.subplot(2,1,1, projection=ccrs.LambertCylindrical(central_longitude=lon_fig_mid))
img1=ax1.contourf(lons1d,lats1d,vals,transform=ccrs.PlateCarree())
ax1.add_feature(cfeature.COASTLINE,edgecolor='brown')
vals_c, lons_c = cutil.add_cyclic_point(vals, coord=lons1d)
ax1=plt.subplot(2,1,2, projection=ccrs.LambertCylindrical(central_longitude=lon_fig_mid))
img1=ax1.contourf(lons_c,lats1d,vals_c,transform=ccrs.PlateCarree())
ax1.add_feature(cfeature.COASTLINE,edgecolor='brown')