【问题标题】:Cartopy, set_extent with NorthPoleStereo not workingCartopy,带有 NorthPoleStereo 的 set_extent 不起作用
【发布时间】:2019-05-22 01:07:45
【问题描述】:

在 Polar Stereo Graphic 地图上使用 set_extent 似乎无法以可预测的方式运行。我正在关注这个Answered StackOverflow 示例,但旋转#yields 都不是地图。我设置了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 能够按照文档说明工作,但似乎在旋转和范围之间存在#a 奇怪的交互

Output

【问题讨论】:

    标签: cartopy


    【解决方案1】:

    这似乎是 CartoPy 如何计算其边界框的神器。当给定 lon/lat 的范围时,它的作用是根据范围计算框的 4 个角,然后将它们投影到本机投影,然后从中计算出范围。问题在于,在立体投影中,由于(尤其是)经度的周期性,其中一些组合最终在 x 或 y 上没有分离。

    我可以仅使用 PyProj 重现数学问题,因此 CartoPy 中的投影数学不是问题,只是它计算边界的方式受到限制。您可以使用set_extent 中的投影坐标覆盖:

    ax.set_extent((0, 500000, 0, 500000), crs=ccrs.NorthPolarStereo())
    

    我知道这并不理想,但我想不出任何好的方法来计算基于 lon/lat 空间中的框的适当边界。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      • 2017-12-25
      • 2017-11-07
      • 2021-09-05
      • 2014-12-10
      • 2011-09-30
      相关资源
      最近更新 更多