matplotlibgeospatialgeocartopygreat-circle

Unexpected behavior from Cartopy


I'm trying to draw a 'straight' line on the surface of the Earth (a great circle), which should appear curved on an orthographic projection that isn't looking straight down on the curve. However, when I try to connect two points with a geodetic line in cartopy I get a line with a kink in it. Where is this kink coming from? And how can I get a correctly rendered great circle segment?

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

lats = [0, 36]
lons = [15, 76]
ax = plt.axes(projection = ccrs.Orthographic(central_longitude=0, central_latitude=45))
ax.plot(lons, lats, transform=ccrs.Geodetic())
ax.set_global()
ax.gridlines()

where is the kink coming from?


Solution

  • From the option transform=ccrs.Geodetic(), the implication is that you need great-circle arc as a result of your ax.plot() statement.

    Without proper setting of projection._threshold you will get the kinked line as you experienced.

    Here is the modified code and the expected result.

    import matplotlib.pyplot as plt
    import cartopy.crs as ccrs
    
    lats = [0, 36]
    lons = [15, 76]
    
    myProj = ccrs.Orthographic(central_longitude=0, central_latitude=45)
    myProj._threshold = myProj._threshold/20. 
    
    ax = plt.axes(projection = myProj)
    ax.plot(lons, lats, transform=ccrs.Geodetic())
    ax.set_global()
    ax.gridlines()
    

    nokink

    Smaller values of the threshold will cause the plotted lines to have denser vertices along the lines. Additional vertices are not obtained by simple interpolation when great-circle arcs are required in this case.