在极地立体图形地图上使用set_extent似乎无法以一种可预测的方式工作。我正在遵循这个Answered StackOverflow示例,但两个旋转#都不会产生映射。我已经设置了ax1.set_global()来显示数据。
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.examples.waves import sample_data
# read sample data
x, y, z = sample_data(shape=(73, 145))
fig = plt.figure(figsize=(8, 8))
# first plot with default rotation. Global extent, works fine
ax1 = fig.add_subplot(221, projection=ccrs.NorthPolarStereo())
cs1 = ax1.contourf(x, y, z, 50, transform=ccrs.PlateCarree(),
cmap='gist_ncar')
ax1.set_title('Global')
#next plot setting extent to 0,360,40,90, no display
ax2 = fig.add_subplot(222,
projection=ccrs.NorthPolarStereo())
cs2 = ax2.contourf(x, y, z, 50,
transform=ccrs.PlateCarree(),
cmap='gist_ncar')
ax2.set_extent([0,360,40,90],crs=ccrs.PlateCarree())
ax2.coastlines()
ax2.set_title('Centred on 0$^\circ$ (default)')
#Now resetting set_extent to [-180,180,40,90] strangely works!
ax3 = fig.add_subplot(
223, projection=ccrs.NorthPolarStereo())
cs3 = ax3.contourf(x, y, z, 50, transform=ccrs.PlateCarree(),
cmap='gist_ncar')
ax3.set_extent([-180, 180, 40, 90], crs=ccrs.PlateCarree())
ax3.coastlines()
ax3.set_title('Using -180,180 $^\circ$W')
#but now rotating projection yields just a corner of the map
ax4 = fig.add_subplot(
224,projection=ccrs.NorthPolarStereo(central_longitude=-45))
cs4 = ax4.contourf(x, y, z, 50, transform=ccrs.PlateCarree(),
cmap='gist_ncar')
ax4.set_extent([-180, 180, 40, 90], crs=ccrs.PlateCarree())
ax4.coastlines()
ax4.set_title('Rotated on -45 $^\circ$W')
plt.show()我原以为set_extent会像文档中描述的那样工作,但似乎在旋转和范围之间有一种奇怪的交互作用
发布于 2019-06-16 06:58:31
这似乎是CartoPy如何计算其边界框的一个工件。当给定经度/纬度的范围时,它所做的是根据范围计算长方体的4个角,然后将这些角投影到本机投影,然后从中计算出范围。问题是,在赤平投影中,由于(特别是)经度的周期性,其中一些组合最终在x或y上没有分隔。
我可以用PyProj重现数学问题,所以这不是CartoPy中投影数学的问题,只是它如何计算边界的限制。您可以通过在set_extent中使用投影坐标来覆盖
ax.set_extent((0, 500000, 0, 500000), crs=ccrs.NorthPolarStereo())我知道这并不理想,但我想不出任何好的方法来计算基于经度/纬度空间中的box的适当界限。
https://stackoverflow.com/questions/56248063
复制相似问题