python - 使用 cartopy.io.img_tiles 穿越日期变更线
问题描述
我试图弄清楚如何使用 Cartopy 和 img_tiles 的地形生成跨越日期线的地图。这是我到目前为止所拥有的:
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy.feature as cfeature
import cartopy.io.img_tiles as cimgt
import shapely.geometry as sgeom
my_dpi = 96
plt.figure(figsize=(1530/my_dpi, 900/my_dpi), dpi=my_dpi, frameon=False)
plt.subplots_adjust(left=0.0, right=1.0, top=1.0, bottom=0)
ax = plt.axes(projection=ccrs.Mercator(central_longitude=180))
terrain = cimgt.Stamen('terrain-background')
ax.add_image(terrain, 4)
states = cfeature.NaturalEarthFeature('cultural', 'admin_1_states_provinces', '10m', edgecolor='darkblue',facecolor='none')
ax.add_feature(states, linewidth = 0.1, linestyle='-')
# draw box
box = sgeom.box(minx=69, maxx=210, miny=-57, maxy=13.5)
ax.add_geometries([box], ccrs.PlateCarree(), facecolor='coral',
edgecolor='black', alpha=0.5)
# Set extent
ax.set_extent(oceania_coords, crs=ccrs.PlateCarree())
plt.show()
当我在要放大的区域周围画一个框时,它看起来是正确的。
当我尝试在此范围内设置 ax.set_extent 时,似乎正确设置了所有 cfeatures 但与 img_tiles 功能搞砸了。
有没有办法解决这个问题?谢谢您的帮助!
解决方案
我有一个对我来说足够好的解决方案,通过关闭两个具有适当比率和边界的子图。接缝上有一个小工件,但我主要在这个框架中切割海洋,所以我没问题。当我将俄罗斯放在框架中时,它就更加明显了。
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy.feature as cfeature
import cartopy.io.img_tiles as cimgt
import shapely.geometry as sgeom
import matplotlib.gridspec as gridspec
my_dpi=96
f = plt.figure(figsize=(1530/my_dpi, 900/my_dpi), dpi=my_dpi, frameon=False)
spec = gridspec.GridSpec(ncols=2, nrows=1,width_ratios=[111,30])
plt.subplots_adjust(left=0.0, right=1.0, top=1.0, bottom=0)
ax1 = f.add_subplot(spec[0],projection=ccrs.Mercator(central_longitude=180))
terrain = cimgt.Stamen('terrain-background')
ax1.add_image(terrain, 3)
states = cfeature.NaturalEarthFeature('cultural', 'admin_1_states_provinces', '10m', edgecolor='darkblue',facecolor='none')
ax1.add_feature(states, linewidth = 0.1, linestyle='-')
ax1.set_extent([69, 180, -57, 13.5], crs=ccrs.PlateCarree())
plt.gca().outline_patch.set_visible(False)
ax2 = f.add_subplot(spec[1],projection=ccrs.Mercator(central_longitude=180))
ax2.add_image(terrain, 3)
ax2.add_feature(states, linewidth = 0.1, linestyle='-')
ax2.set_extent([-180,-150, -57, 13.5], crs=ccrs.PlateCarree())
plt.gca().outline_patch.set_visible(False)
plt.subplots_adjust(wspace=0)
推荐阅读
- python - 无法解决 Python ImportError: cannot import name 'FirstNews'
- javascript - Fancybox 画廊打破 swiper
- jenkins - Jenkins:Jenkins 在哪里存储分配的用户(ldap 用户)的配置文件?
- c# - 如何创建一个包含 n 个字符串属性和一个数据对象的对象列表,但对象类型及其属性可以在 C# 中动态更改
- spring - 我无法在 Spring 中通过 Thymeleaf 以 HTML 格式显示图像
- animation - Flutter TabBarView的动画持续时间
- arduino - 中断运行时Arduino不会休眠
- git - 为什么 First Commit (Root Commit) 的时间戳大于 Second Commit?
- java - 版本 8 及更高版本的 OpenJDK 安全更新
- json - ORM: Sequelize: 除了一些 json 数据,我如何返回?