首页 > 解决方案 > 用 Cartopy 绘制细粒度测地线

问题描述

以下代码(从此处复制)在纽约市和新德里之间生成​​了一个漂亮的测地线。仔细检查后,测地线看起来并不平滑。我怎样才能使它看起来光滑?

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

ny_lon, ny_lat = -75, 43
delhi_lon, delhi_lat = 77.23, 28.61

ax = plt.axes(projection=ccrs.PlateCarree())
ax.stock_img()

plt.plot([ny_lon, delhi_lon], [ny_lat, delhi_lat],
         linewidth=2, marker='o', transform=ccrs.Geodetic())
plt.tight_layout()
plt.show()

破碎的测地线

标签: python-3.xcartopy

解决方案


您需要沿绘制的测地线设置更精细的线段阈值。这是执行此操作的相关代码行。

plateCr = ccrs.PlateCarree()
# print(plateCr._threshold) # original threshold=0.5
plateCr._threshold = plateCr._threshold/10.  #set finer threshold
ax = plt.axes(projection=plateCr)

换行:

ax = plt.axes(projection=ccrs.PlateCarree())

使用上面建议的代码。结果图应如下所示:

在此处输入图像描述


推荐阅读