Search code examples
pythongiscartopy

cartopy: zoom in to a region


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:

enter image description here

What I want (zoomed-in version):

enter image description here

Is there anyway to do this?


Solution

  • You can use ax.set_extent()

    ax.set_extent([-150, -20, -90, 90])