如何在以下代码中获取“句柄”-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()”的输出,因为这只会打印出我原来的经度和纬度,而是在寻找在地图上绘制的大地测量线的数据。
答案 0 :(得分: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)
在回答这个问题时,还有第二种方法。