我有一个使用Cartopy贴图作为坐标系的绘图.我想单击图上的任何位置,标记它,并返回单击点的纬度和经度位置.I am just not sure how to transform the event data back to map coordinates.
我已经把Matplotlib Transformations Tutorial看了一遍,但我仍然不清楚.绘图上的导航工具栏甚至以经度/经度显示坐标,但我不确定如何访问它.
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig = plt.figure()
ax = plt.axes(projection=ccrs.Sinusoidal())
ax.set_extent([0,10,0,10], crs=ccrs.PlateCarree())
ax.gridlines(draw_labels=True,dms=True,x_inline=False,y_inline=False)
def onclick(event):
ax.scatter(event.xdata, event.ydata)
fig.canvas.draw()
# I want to print xdata and ydata in terms of Latitude and Longitude
print(event.xdata,event.ydata)
cid = fig.canvas.mpl_connect('button_press_event', onclick)