I'm trying to plot map with contourf that could go further than 180° Est without the bounaries having to start from the other side of the world (I'll clarify with figures after showing the code).
Here is my code to plot the maps :
def plot_geog_location(region, lakes=False, borders=False, rivers=False):
lonmin,lonmax,latmin,latmax = region.lonmin,region.lonmax,region.latmin,region.latmax
ax = plt.figure().gca(projection=cartopy.crs.PlateCarree())
CS = plt.contourf(lons, lats, AOD[:,:],levels=level, extend='both',cmap=plt.cm.Oranges, norm=colors.PowerNorm(gamma=0.4),shading='auto')
plt.title('AOD average over Australia 02-06 Jan 2020 (MERRA-2)',fontsize=16)
plt.gcf().set_size_inches(15, 11)
cbar = plt.colorbar(CS, shrink=0.45,ticks=[0,1,2,3,4,5])
cbar.ax.set_yticklabels(['0','1', '2','3','4','5'])
ax.add_feature(cpf.COASTLINE)
ax.add_feature(cfeature.STATES, zorder=1, linewidth=1, edgecolor='k',linestyle=':')
if borders:
ax.add_feature(cpf.BORDERS, linestyle='--')
ax.set_extent([lonmin, lonmax, latmin, latmax])
# plot the lat lon labels
# https://scitools.org.uk/cartopy/docs/v0.15/examples/tick_labels.html
# https://stackoverflow.com/questions/49956355/adding-gridlines-using-cartopy
xticks = np.linspace(lonmin, lonmax, 5)
yticks = np.linspace(latmin, latmax, 5)
ax.set_xticks(xticks, crs=cartopy.crs.PlateCarree())
ax.set_yticks(yticks, crs=cartopy.crs.PlateCarree())
lon_formatter = LongitudeFormatter(zero_direction_label=True)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
fig = plt.gcf()
return fig, ax
So basicaly this produce the following map with max longitude = 180 :
And when if i want to observe the transport of my AOD further Est by changing my longitude max to 200 or -160 (which is the same value) I got the following :
Any idea how I could resolve this problem ? I can post my whole code if necessary
EDIT : Actually, there is an argument for cartopy.crs.PlateCarree() called 'central_longitude' where I can reassign it to 180 and it seems to be working this way, but it made all my data being moved 180° farther so I'm still looking for a solution...
If I give the 'central_longitude' argument 180 value and add +180 to my data longitude : lons=sd['lon']+180 it's working pretty well. It's just a way to overcome the problem but not really a solution tho.