我如何获得一个大地测量图的变换数据?

问题描述 投票:1回答:1

如何在下面的代码中获取“句柄”-Line2D对象的转换行的所有数据:

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

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

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

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

要更清楚:我不是在寻找“ handle [0] .get_data()”的输出,因为这只是打印出我原来的经度和纬度,而是在寻找地图上绘制的大地测量线的数据。

python matplotlib cartopy
1个回答
0
投票

我找到了答案!根据此question,您可以通过以下代码段访问转换数据:

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

t_path = handle._get_transformed_path()

path_in_data_coords, _ = t_path.get_transformed_path_and_affine()
print(path_in_data_coords.vertices)

在回答这个问题时,还有第二种方法。

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