Search code examples
pythoncartopy

drawing great circle path with cartopy


I'm supposed to draw a map using cartopy. The assignment is:

Use the orthographic projection, centered on Hamburg, and draw the great circle path between Hamburg and Tokyo

import cartopy
import cartopy.crs as ccrs

ax = plt.axes(projection=ccrs.Orthographic(central_longitude = long_ham, central_latitude = lat_ham))
ax.coastlines()


long_ham, lat_ham = 9.993682, 53.551086
long_tok, lat_tok = 139.839478, 35.652832

plt.plot([long_ham, long_tok], [lat_ham, lat_tok],
         color='blue', linewidth=2, marker='o',
         transform=ccrs.Geodetic(),
         )

plt.text(long_ham , lat_ham , 'Hamburg',
         horizontalalignment='right',
         transform=ccrs.Geodetic())

plt.text(long_tok , lat_tok , 'Tokyo',
         horizontalalignment='left',
         transform=ccrs.Geodetic())

# Save the plot by calling plt.savefig() BEFORE plt.show()
plt.savefig('great circle distance.pdf')
plt.savefig('great circle distance.png')

plt.show()

this is the result

Is there a way to show the whole globe instead of the close up that I'm currently getting?


Solution

  • You need to set ax.set_global() before savefig() and plt.show().

    global