Cartopy set_extent 修剪圆的边缘

问题描述 投票:0回答:1

在 Spyder 中使用 Cartopy 和 matplotlib,这两行:

fig=plt.figure(1, figsize=(12,8)) 
ax1 = fig.add_subplot(1, 3, 1, projection=ccrs.Orthographic(central_latitude=-90,central_longitude=0))

产生我想要的圆形图。 (circular edge, good)

但是执行下一行之后:

ax1.set_extent([lon_ref.min(),lon_ref.max(),lat_ref.min(),lat_ref.max()], crs=ccrs.PlateCarree())

我发现我的图显示了修剪过的边缘,因此不再是圆形的。 (trimmed edges, bad)

为什么会发生这种情况?我该如何修改它以保持我的情节循环?

谢谢你。

我尝试更改纬度范围,但这并不能解决问题。

python matplotlib spyder cartopy
1个回答
0
投票

您可能应该设置一个圆形边界,如本示例此处所示。另外,您应该记住,您是从一侧(即从南极侧)看地球,这对可用于设置地图范围的经度和纬度范围造成了一些限制。在任何情况下,您可能需要显示一些网格线和海岸线,以更好地了解各种范围值如何改变您的绘图。这是一个具有两个不同范围值(左和右)和边界类型(顶部和底部)的示例:

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 plots with different extents
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 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 plots with different extents 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()

圆形边界(底部子图)似乎阻止了“边缘修剪”:

© www.soinside.com 2019 - 2024. All rights reserved.