The code below produces a map of the North Atlantic Ocean. However, the latitude labels are misplaced (want them outside, not inside) and not on both sides. I think this has to do with how I set the extent, but I do not know any other way to get this conic shape I want.
I would appreciate any answer to one or both of these questions:
- Is there a better way to set the extent to get that conic shape?
- How can I have my y-labels on the left and outside the figure?
# Import modules
import cartopy
import cartopy.crs as ccrs
import matplotlib.path as mpath
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
# Define projections
dataproj = ccrs.PlateCarree()
mapproj = ccrs.Stereographic(central_longitude=-30)
# Plot figure
fig = plt.figure()
ax = plt.axes(projection=mapproj)
# Add some features
ax.add_feature(cartopy.feature.LAND, edgecolor='black')
ax.add_feature(cartopy.feature.OCEAN)
###
# I want to have kind of a conic shape. I manage to do this by adapting some code from
# https://stackoverflow.com/a/65690841/9970523
#
# Lon and Lat Boundaries
xlim = [-60, 0]
ylim = [50, 65]
lower_space = 3
rect = mpath.Path([[xlim[0], ylim[0]],
[xlim[1], ylim[0]],
[xlim[1], ylim[1]],
[xlim[0], ylim[1]],
[xlim[0], ylim[0]],
]).interpolated(20)
proj_to_data = ccrs.PlateCarree()._as_mpl_transform(ax) - ax.transData
rect_in_target = proj_to_data.transform_path(rect)
ax.set_boundary(rect_in_target)
ax.set_extent([xlim[0], xlim[1], ylim[0] - lower_space, ylim[1]])
#
# End of https://stackoverflow.com/a/65690841/9970523
###
# lats/lons labels and ticks
gl = ax.gridlines(crs=ccrs.PlateCarree())
gl.xlocator = mticker.FixedLocator([-60, -45, -30,-15, 0])
gl.ylocator = mticker.FixedLocator([50, 55, 60, 65])
gl.bottom_labels = True
gl.left_labels = True
gl.top_labels = True
gl.right_labels = True