Using Cartopy & matplotlib in Spyder, these 2 lines :
fig=plt.figure(1, figsize=(12,8))
ax1 = fig.add_subplot(1, 3, 1, projection=ccrs.Orthographic(central_latitude=-90,central_longitude=0))
produces the circular plot I want. (circular edge, good)
But after executing the next line :
ax1.set_extent([lon_ref.min(),lon_ref.max(),lat_ref.min(),lat_ref.max()], crs=ccrs.PlateCarree())
I find that my plot shows trimmed edges and is therefore no longer circular. (trimmed edges, bad)
How come this happens and how can I modify this to keep my plot circular?
Thank you.
I tried to change the extents in latitude, but it doesn't solve the problem.
You should probably set a circular boundary like in this example here. Also, you should remember you are looking at the South pole of the globe, which puts some limits on the range of longitudes and latitudes you can use to set the map extent (e.g. you cannot extend the maximum latitude beyond 0). In any case, you may need to show some gridlines and coastlines, to understand better how various extent values change your plot. Here is an example with two different extent values (left and right) and boundary types (top and bottom):
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import numpy as np
import matplotlib.path as mpath
# we are looking at the southern pole of the globe
projection = ccrs.Orthographic(central_latitude=-90, central_longitude=0)
# two extents we are going to work with
extent_big = [-180, 180, -90, -0.3] # max latitude doesn't seem to be able to go beyond -0.3 without destroying the plot
extent_small = [-180, 180, -90, -60]
fig=plt.figure(1, figsize=(12, 10))
# two top plots with different extents (left and right)
ax1 = fig.add_subplot(2, 2, 1, projection=projection)
ax1.set_extent(extent_big, crs=ccrs.PlateCarree())
ax1.coastlines(color='b')
ax1.gridlines(draw_labels=True)
ax1.set_title('Extent {}'.format(extent_big), color='r')
ax2 = fig.add_subplot(2, 2, 2, projection=projection)
ax2.set_extent(extent_small, crs=ccrs.PlateCarree())
ax2.coastlines(color='b')
ax2.gridlines(draw_labels=True)
ax2.set_title('Extent {}'.format(extent_small), color='r')
# make a circular map boundary in axes coordinates
theta = np.linspace(0, 2 * np.pi, 100)
center, radius = [0.5, 0.5], 0.5
verts = np.vstack([np.sin(theta), np.cos(theta)]).T
circle = mpath.Path(verts * radius + center)
# two bottom plots with different extents (left and right) limited by the circular boundary
ax3 = fig.add_subplot(2, 2, 3, projection=projection)
ax3.set_boundary(circle, transform=ax3.transAxes)
ax3.set_extent(extent_big, crs=ccrs.PlateCarree())
ax3.coastlines(color='b')
ax3.gridlines(draw_labels=True)
ax3.set_title('Extent {}, circular boundary:'.format(extent_big), color='r')
ax4 = fig.add_subplot(2, 2, 4, projection=projection)
ax4.set_boundary(circle, transform=ax4.transAxes)
ax4.set_extent(extent_small, crs=ccrs.PlateCarree())
ax4.coastlines(color='b')
ax4.gridlines(draw_labels=True)
ax4.set_title('Extent {}, circular boundary:'.format(extent_small), color='r')
plt.show()
Circular boundary (bottom subplots) seems to prevent that "edge trimming":