ChaoLiu
ChaoLiu

Reputation: 21

Why does Cartopy show an incomplete boundary for the Robinson projection under different central longitude values?

I am trying to use the cartopy (version=0.21.0) package to draw global data map using the Robinson projection. However, when I choose differnt central longitude values for the projection method, the produced figures show asymmetric left & right boundaries in some cases.

Specifically, the figures look correct when I use a central longitude value of -110, -120, -130, but they show asymmetric boundaries as the central longitude value becomes smaller (e.g., -140, -150, -160). I have used the "add_cyclic_point" function to wrap the global data in a zonal direction before drawing. I also tried to set map extent inspired by the answer of @geofisue.The main codes and figures are attached as follows:

import matplotlib.pyplot as plt
import xarray as xr 
import cartopy.crs as ccrs
from cartopy.util import add_cyclic_point

fname = 'sst.nc'
with xr.open_dataset(fname) as f:
    sst = f['sst'].isel(time=0)
    sst = sst.sel(lat=slice(-60,60))

lonc = [-110, -120, -130, -140, -150,-160]
for i in range(6):
    ax = plt.subplot(321+i, projection=ccrs.Robinson(central_longitude=lonc[i]))
    
    # wrap the global 
    wsst, wlon = add_cyclic_point(sst, coord=sst.lon.data)
    handle = ax.contourf(wlon, sst.lat, wsst, transform=ccrs.PlateCarree())
    ax.set_title('lon-cent = {:d}'.format(lonc[i]))
    ax.coastlines(resolution='110m', color='0.7', lw=1)
    ax.axhline(0, ls='--', color='k', lw=0.8)
    #ax.set_global()
    
plt.show()

below are generated figures with asymmetric boundaires marked.

1. cartopy-robinson global data with no set_global option cartopy-robinson global data with no set_global option

2. cartopy-robinson latitude-sliced data with no extent setting cartopy-robinson latitude-sliced data with no extent setting

3. cartopy-robinson latitude-sliced data with set_global() option cartopy-robinson latitude-sliced data with set_global() option

I would expect the figures to have exactly the same symmetrical left and right boundaries under different central longitudes even with latitude-sliced data.

All suggestions and comments are welcome.

Upvotes: 2

Views: 400

Answers (1)

geofisue
geofisue

Reputation: 165

My guess is that this is related to extent of the plot due to the data used. I am not using data, but add a ax.set_global() in order to show the whole globe.

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.util import add_cyclic_point

lonc = [-110, -120, -130, -140, -150,-160]
plt.figure(figsize=(10,6))
for i in range(6):
    ax = plt.subplot(321+i, projection=ccrs.Robinson(central_longitude=lonc[i]))
    ax.set_title('lon-cent = {:d}'.format(lonc[i]))
    ax.coastlines(resolution='110m', color='0.7', lw=1)
    ax.axhline()
    ax.set_global()
    
plt.show()

enter image description here

Upvotes: 1

Related Questions