Yair Daon
Yair Daon

Reputation: 1133

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

Upvotes: 3

Views: 1037

Answers (1)

swatchai
swatchai

Reputation: 18812

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

Upvotes: 6

Related Questions