Problem with Plotting NetCDF Dataset Over International Date Line Using Matplotlib and Cartopy

Hello everyone,

At my current job I’m working on trying to create several PNG files for a set of geographic domains from a NetCDF file using Xarray, Cartopy, and matplotlib and I’m running into an issue where several of the subdomains aren’t rendering properly when they cross the international date line. I’ve tried setting an international date line centered projection via ccrs.PlateCarree(central_longitude=180) but while the underlying map does recenter to the correct domain, the data remains untransformed and instead shows the grid subset around the prime meridian instead. I’m using plt.imshow() to render the grid (this is because of custom color bar placement and grid spacing). I also made sure to pass the projection via the transform keyword to plt.imshow(), but still no dice. I’ve tried nearly every avenue to try and solve this problem but honestly I have no clue how to fix this problem. All the other geographic domains I’m creating plots for work fine, it’s only about 4 of them that cross the date line that are causing this issue. Any help or advice anyone could provide I would greatly appreciate it. Thanks!

Hi. Sometimes the problem is in the way the coordinates are defined in the netCDF files and not in the plotting interface. Have you checked those? There are some conventions.

Please share more details about the data, e.g.

ds = xr.open_dataset("myfile.nc")
print(ds)
1 Like