简体   繁体   English

如何用Cartopy的NearsidePerspective投影拟合Matplotlib的stock_img()

[英]How to fit Matplotlib's stock_img() with Cartopy's NearsidePerspective projection

I am trying to use Cartopy's proejction NearsidePerspective, but overlaping with the real Earth image provided by Matplotlib, and zooming in a bit by lowering the satellite_height parameter. 我正在尝试使用Cartopy的protojction NearsidePerspective,但与Matplotlib提供的真实地球图像重叠,并通过降低satellite_height参数进行了放大。 It appears that Cartopy is not able to trim the image properly for this specific type of setting. 对于这种特定类型的设置,Cartopy似乎无法正确修剪图像。 The image is displayed still oustide of what one would expect to be the map boundaries. 图像仍被替换为预期的地图边界。

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

fig=plt.figure(figsize=(10,10))

# Set Projection
height=3000000 
#height=35785831 # this is the default height
projection=ccrs.NearsidePerspective(central_longitude=120,
                                    central_latitude=78,
                                    satellite_height=height)
# Draw 
ax = plt.axes(projection=projection)
ax.stock_img()
ax.coastlines(resolution='50m')
plt.show()

在此处输入图片说明

How can I combine Matplotlib's stock_img() and this configuration of NearsidePerspective to work properly? 如何结合Matplotlib的stock_img()和NearsidePerspective的此配置才能正常工作? Or what would be an alternative way to get the result desired? 还是获得期望结果的替代方法是什么?

I am using Python 3.6 on Jupyter Notebook, Matplotlib 3.0.2, and Cartopy 0.16.0. 我在Jupyter Notebook,Matplotlib 3.0.2和Cartopy 0.16.0上使用Python 3.6。

Using the same code on a mac with Python 3.7, Matplotlib 3.0.3, and Cartopy 0.17.0, the image is cropped correctly: 在Mac上使用Python 3.7,Matplotlib 3.0.3和Cartopy 0.17.0使用相同的代码,可以正确裁剪图像:

OP代码的结果

This may either be a version problem or with Jupyter Notebook. 这可能是版本问题,也可能是Jupyter Notebook出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM