Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot Fine Grained Geodesic with Cartopy

The following code (copied from here) produces a nicely looking geodesic between NYC and New Delhi. Upon close inspection, the geodesic does not look smooth. How can I make it smooth looking?

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

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

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

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

broken geodesic

like image 767
Yair Daon Avatar asked Sep 15 '26 16:09

Yair Daon


1 Answers

You need to set a finer threshold of the line segments along the plotted geodesic line. Here is the relevant lines of code to do so.

plateCr = ccrs.PlateCarree()
# print(plateCr._threshold) # original threshold=0.5
plateCr._threshold = plateCr._threshold/10.  #set finer threshold
ax = plt.axes(projection=plateCr)

Replace the line:

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

with the proposed code above. The result plot should look like this:

enter image description here

like image 75
swatchai Avatar answered Sep 18 '26 18:09

swatchai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!