cartopy:放大到一个区域

xia*_*012 2 python gis cartopy

我想使用 Cartopy 仅绘制一个区域(在我的情况下,北美和南美)。

我目前正在使用以下代码:

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())
Run Code Online (Sandbox Code Playgroud)

然后它产生:

在此处输入图片说明

我想要的(放大版):

在此处输入图片说明

有没有办法做到这一点?

小智 6

您可以使用ax.set_extent()

ax.set_extent([-150, -20, -90, 90])
Run Code Online (Sandbox Code Playgroud)

  • 在设置范围时包含一个 `crs` 是一个很好的做法,这样如果投影改变,代码仍然可以工作,尽管在这个例子中结果是一样的:`ax.set_extent([-150, -20, -90, 90], crs=ccrs.PlateCarree())` (5认同)