如何在Cartopy的地图上绘制填充的多边形

问题描述 投票:0回答:2

编辑,添加答案中的建议

我有一个经度/纬度的顶点列表,这些顶点定义了地图上多边形的角。我想使用cartopy在地图上绘制该多边形,其边缘是大圆。我尝试按照https://scitools.org.uk/cartopy/docs/v0.5/matplotlib/introductory_examples/02.polygon.html的示例进行操作,但无法正常工作。这是到目前为止我尝试过的:

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import matplotlib.patches as mpatches

map_proj = ccrs.Orthographic(central_latitude=0.0, central_longitude=80.0)
ax = plt.axes(projection=map_proj)

ax.set_global() # added following an answer to my question
ax.gridlines()

ax.coastlines(linewidth=0.5, color='k', resolution='50m')

lat_corners = np.array([-20.,  0., 50., 30.])
lon_corners = np.array([ 20., 90., 90., 30.]) + 15.0 # offset from gridline for clarity

poly_corners = np.zeros((len(lat_corners), 2), np.float64)
poly_corners[:,0] = lon_corners
poly_corners[:,1] = lat_corners

poly = mpatches.Polygon(poly_corners, closed=True, ec='r', fill=False, lw=1, fc=None, transform=ccrs.Geodetic())
ax.add_patch(poly)

Output image

注意,这些线不是大圆,并且似乎有四个以上的顶点。我觉得这是一件很简单的事情,必须有一种方法,但我无法从Cartopy文档中找出来。

matplotlib cartopy
2个回答
0
投票

请注意,示例使用

ax.set_global()

0
投票

我认为这可能是因为Cartopy的默认变换分辨率对于此投影而言太低。您可以通过强制采用更高的分辨率来解决此问题:

map_proj = ccrs.Orthographic(central_latitude=0.0, central_longitude=80.0)
map_proj._threshold /= 100.
...

这会产生漂亮的弯曲大圆弧。

© www.soinside.com 2019 - 2024. All rights reserved.