I would like to use Cartopy to plot only a region (in my case, North and South America).
I am currently using the following code:
import cartopy
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
lon, lat, freq = .., ..., ... # initialize longitude and latitude and line width
ax = plt.axes(projection=ccrs.PlateCarree())
ax.stock_img()
ax.add_feature(cartopy.feature.LAND)
ax.add_feature(cartopy.feature.OCEAN)
ax.add_feature(cartopy.feature.COASTLINE)
ax.add_feature(cartopy.feature.BORDERS, linestyle='-', alpha=.5)
for la, lo, fq in zip(lat, lon, freq):
plt.plot(lo, la, color='red', linewidth=fq, marker='o', transform=ccrs.PlateCarree())
Then it produces:
What I want (zoomed-in version):
Is there anyway to do this?
You can use ax.set_extent()
ax.set_extent([-150, -20, -90, 90])