Gridlines in cartopy Stereographic projection

I am making a figure with a map of East Anatrctica but Cartopy shows only western meridians by default.

midlon = -225
maxlon = midlon + 60
minlon = midlon - 60
minlat = -78
maxlat = -50
midlat = (minlat + maxlat) / 2

norm = mcolors.TwoSlopeNorm(vmin=0, vcenter=0.25, vmax=1)

projection = ccrs.Stereographic(central_longitude=midlon, central_latitude=midlat)

fig = plt.figure(figsize=(12, 6.5))
ax = plt.axes(projection=projection)

ax.add_feature(land_50m)
ax.coastlines(resolution="50m")
ax.set_extent([minlon, maxlon, minlat, maxlat], crs=ccrs.PlateCarree())

lons = X.sel(
    {"xt_ocean": slice(minlon, maxlon), "yt_ocean": slice(minlat, maxlat)}
)
lats = Y.sel(
    {"xt_ocean": slice(minlon, maxlon), "yt_ocean": slice(minlat, maxlat)}
)

boundary_path = make_boundary_path(lons, lats)
ax.set_boundary(boundary_path, transform=ccrs.PlateCarree())

gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, x_inline=False, y_inline=False, linewidth=0.33, color='k',alpha=0.5)
gl.right_labels = gl.top_labels = False

If I add custom ticks:

gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, x_inline=False, y_inline=False, linewidth=0.33, color='k',alpha=0.5)
gl.right_labels = gl.top_labels = False
gl.left_labels = gl.bottom_labels = True

gl.xlocator = mticker.FixedLocator([100, 120, 140, 160])  # Longitudes in degrees east
gl.ylocator = mticker.FixedLocator([-70, -60, -50])  # Latitudes

it shows only parts of parallels but no meridians.

I’d be happy just with ticks (not actual gridlines) at this point but I can’t figure out how to show eastern meridians in this case.

Pure speculation, but is this because of where your data wraps?

Could you wrap your data around so that it is symmetrical about zero in longitude? Or maybe so that it is symmetrical about 180 in longitude (so from 0-360).

1 Like

Assigned until Aidan confirms.

I’d have the same speculation.

1 Like

HI @polinash. Just to be explicit, your question isn’t inscope for ACCESS-NRI Support because it doesn’t relate to our supported tools or releases.

Hopefully either my suggestion will help, or someone else will be able to assist.

Issue is in cartopy apparently set_boundary of GeoAxes breaks gridlines when the dateline is crossed · Issue #1831 · SciTools/cartopy · GitHub

2 Likes