Ad
Cartopy: Convert Point From Axes Coordinates To Lat/lon Coordinates
I am working on a map plot with Cartopy (TransverseMercator
projection). I have a point in axes coordinates (p_a = (0.1, 0.9)
) and I need its lat/lon coordinates (i.e., those in PlateCarree
projection). How can I achieve this?
Ad
Answer
For this you need to transform the point from axes coordinates to display coordinates, then to data coordinates, and finally to lat/ lon coordinates. Thus you need transformations from matplotlib and cartopy.
The point p_a = (0.1, 0.9)
seems to be outside of valid lat/ lon coordinates (for the default ccrs.TransverseMercator()
). Therefore I use p_a = (0.6, 0.6)
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
proj = ccrs.TransverseMercator()
proj_cart = ccrs.PlateCarree()
f, ax = plt.subplots(subplot_kw=dict(projection=proj))
ax.coastlines()
# define point
p_a = (0.6, 0.6)
# plot point in Axes coordinates
ax.plot(*p_a, transform=ax.transAxes, marker='o', ms=10)
# convert from Axes coordinates to display coordinates
p_a_disp = ax.transAxes.transform(p_a)
# convert from display coordinates to data coordinates
p_a_data = ax.transData.inverted().transform(p_a_disp)
# convert from data to cartesian coordinates
p_a_cart = proj_cart.transform_point(*p_a_data, src_crs=proj)
# make sure we are correct
ax.plot(*p_a_cart, transform=proj_cart, marker='x', ms=10)
This yields the following figure:
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad