首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cartopy,NorthPoleStereo不工作的set_extent

Cartopy,NorthPoleStereo不工作的set_extent
EN

Stack Overflow用户
提问于 2019-05-22 09:07:46
回答 1查看 726关注 0票数 2

在极地立体图形地图上使用set_extent似乎无法以一种可预测的方式工作。我正在遵循这个Answered StackOverflow示例,但两个旋转#都不会产生映射。我已经设置了ax1.set_global()来显示数据。

代码语言:javascript
复制
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会像文档中描述的那样工作,但似乎在旋转和范围之间有一种奇怪的交互作用

Output

EN

回答 1

Stack Overflow用户

发布于 2019-06-16 06:58:31

这似乎是CartoPy如何计算其边界框的一个工件。当给定经度/纬度的范围时,它所做的是根据范围计算长方体的4个角,然后将这些角投影到本机投影,然后从中计算出范围。问题是,在赤平投影中,由于(特别是)经度的周期性,其中一些组合最终在x或y上没有分隔。

我可以用PyProj重现数学问题,所以这不是CartoPy中投影数学的问题,只是它如何计算边界的限制。您可以通过在set_extent中使用投影坐标来覆盖

代码语言:javascript
复制
ax.set_extent((0, 500000, 0, 500000), crs=ccrs.NorthPolarStereo())

我知道这并不理想,但我想不出任何好的方法来计算基于经度/纬度空间中的box的适当界限。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56248063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档