matplotlib AlbersEqualArea使用经度和纬度限制区域

hzbexzde  于 2023-05-01  发布在  其他
关注(0)|答案(1)|浏览(162)

我有经度-100o -30o和纬度0 o-80 o的数据。
我想用投影只显示这个区域。
在我的脑海中,我想展示一个这样的情节:

但是,当我尝试AlbersEqualArea投影时,如下所示:

plt.figure(figsize=(5.12985642927, 3))
ax = plt.axes(projection=ccrs.AlbersEqualArea(central_longitude=-35, central_latitude=40, standard_parallels=(0, 80)))    
ax.set_extent([lon180[0], lon180[-1], lat[0], lat[-1]], ccrs.Geodetic())

我得到一张Map,上面显示:

如何显示我拥有数据的区域?

6xfqseft

6xfqseft1#

如果你想有一个非矩形的边界,你必须自己定义它。以下内容可能对您有用:

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import matplotlib.path as mpath

proj = ccrs.AlbersEqualArea(central_longitude=-35,
                            central_latitude=40,
                            standard_parallels=(0, 80))
ax = plt.axes(projection=proj)    
ax.set_extent([-100, 30, 0, 80], crs=ccrs.PlateCarree())
ax.coastlines()

# Make a boundary path in PlateCarree projection, I choose to start in
# the bottom left and go round anticlockwise, creating a boundary point
# every 1 degree so that the result is smooth:
vertices = [(lon, 0) for lon in range(-100, 31, 1)] + \
           [(lon, 80) for lon in range(30, -101, -1)]
boundary = mpath.Path(vertices)
ax.set_boundary(boundary, transform=ccrs.PlateCarree())

plt.show()

相关问题