The numerous external libraries available for Python continue impressing me, in scope, numbers and ease of use. A couple of hours ago I googled for chartographic tools for Python, and found the Basemap-library, an add-on to Matplotlib. For whatever reason, it’s not available for pip install, so I had to install it from sources, which was totally painless. Then, after finding this basemap tutorial, it took just about 15 lines of code and equally long time in minutes to draw the different map projections above, all showing a flight path Stockholm – San Francisco.
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
lat1,lon1 = 59.6498,17.9238 #arn
lat2,lon2 = 37.6213,-122.3790 #sfo
map = Basemap(
width=30e6,height=30e6,resolution=’i’,projection=’vandg’,lat_1=30,lat_2=80,lat_0=60,lon_0=-30)
map.drawmapboundary(fill_color=’aqua’)
map.fillcontinents(color=’coral’,lake_color=’aqua’)
map.drawcoastlines()
map.drawparallels(np.arange(10,90,20))
map.drawmeridians(np.arange(-180,180,15))
x,y = map(17.9238,59.6498)
x2,y2 = map(-122.3790,37.6213)
map.plot(x,y,’bo’)
map.plot(x2,y2,’bo’)
map.drawgreatcircle(lon1,lat1,lon2,lat2,color=’b’)
plt.title(‘van der Grinten Projection’)
plt.show()