I’ve been unable to find online information that clarifies for me how to do the following seemingly simple task:
Given user-specified (central_lat, central_lon) and geographic radius in units of distance (or more conveniently, degrees latitude DR), set the plotting extent for a stereographic projection centered on (central_lat, central_lon) and with square plot limits just enclosing the specified radius.
I’ve done this sort of thing easily with simpler map plotting systems, in which the orthographic projection maps lat/lon to a cartesian coordinate system with the origin at (central_lat, central_lon).
In pseudocode:
- Set orthographic project centered on (central_lat, central_lon)
- Find cartesian coordinates (X0, Y0) at (central_lat, central_lon)
- Find cartesian coordinates (X0, Y0+DY) at (central_lat + DR, central_lon)
- Set plot extent to [X0-DY, X0+DY, Y0-DY, Y0+DY)
I’ve tried various combinations of projections and transform methods, but I seem not to have found the one that gets me from lat/lon to cartesian (not display) coordinates and that can be used to set the plot extent.
Here are some code fragments to help orient anyone reading:
clat = 40
clon = -90
DR = 20 # plot has a radius equivalent to DR degrees
proj = ccrs.Orthographic(central_latitude=clat, central_longitude=clon)
data_proj = ccrs.PlateCarree()
fig = plt.figure(figsize=(14, 14))
m = plt.axes(projection=proj)
.... # get transformed limits here somehow
extent = [X0, X1, Y0, Y1] # Cartesian coordinates
m.set_extent(extent, proj) # ??? or some other projection here
...