Search code examples
pythonmatplotlibevent-handlingcartopy

Getting mouseposition in longitude and latitude in cartopy (python)


I am trying to get the mouse position's longitude and latitude using cartopy via the standard matplotlib event handling. But when my button_press_event fires, event.x just gives the pixel position in the figure (as usual) and event.xdata some arbitrary numbers I cant really define, but definately nothing between 180°W and 180°E.

So how could I get the longitude/latitude position of the mousecursor in Mercator projection?


Solution

  • Basically this answers the question:

    Obtaining coordinates in projected map using Cartopy

    Cartopy apparently does use some other coordinate system when using the Mercator projection. When transforming back to the PlateCarree projection, it transforms the "arbitrary numbers" back into lat/lon pairs.