# Create Globes to Display Global Gravity Data¶

Joseph Barraud

This notebook explains how to make maps in orthographic projection with matplotlib basemap and cartopy. The interpies library is also used to load the data and create images. interpies is available here.

Note: For this notebook to work, you need to install interpies and its dependencies, as well as basemap and cartopy. Using conda, that should be as easy as writing:

conda install basemap
conda install cartopy


The orthographic projection is typically the one that results in an image of the Earth as a globe floating in space. Provided you have the right image, it is relatively easy to warp it around the globe and make a map that looks both interesting and unusual.

Let's start by importing the interpies module, basemap, cartopy and a few others.

In [1]:
import sys, os
import numpy as np
import imageio
from matplotlib import pyplot as plt

# basemap
from mpl_toolkits.basemap import Basemap

# cartopy
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature

# interpies
import interpies
interpies.__version__

Out[1]:
'0.3.1'
In [2]:
# plot within the notebook
%matplotlib inline


## Basic globe¶

This first example simply shows the setup for creating a map in orthographic projection. Both basemap and cartopy provide coastlines and other vector layers to add some context.

### With basemap¶

The orientation of the globe is controlled by the two parameters lat_0 and lon_0.

In [3]:
fig, ax = plt.subplots(figsize=(10,10))
m = Basemap(projection='ortho', lat_0=45, lon_0=0, resolution='c', ax=ax)

# draw coastlines and borders
m.drawcoastlines()
m.drawcountries()

# draw meridians and parallels
m.drawmeridians(np.arange(0,360,30))
m.drawparallels(np.arange(-90,90,30))
plt.show()

C:\Anaconda3\envs\interpies_test\lib\site-packages\mpl_toolkits\basemap\__init__.py:1711: MatplotlibDeprecationWarning: The axesPatch function was deprecated in version 2.1. Use Axes.patch instead.
if limb is not ax.axesPatch:


### With cartopy¶

Similarly, the orientation of the globe is controlled by parameters of the projection class.

Regarding meridians and parallels, the defaults are different but I tried to reproduce the behaviour of basemap here.

In [4]:
fig = plt.figure(figsize=(10, 10))
ax = plt.axes(projection=ccrs.Orthographic(0, 45))

# draw coastlines and borders
# draw meridians and parallels
gl = ax.gridlines(color='k', linestyle=(0, (1, 1)), xlocs=range(0,390,30), ylocs=[-80, -60, -30, 0, 30, 60, 80])


## Globe with ETOPO image¶

basemap has a built-in function to add the Global Relief Model ETOPO from the NOAA to the map. There is also a similar function to display the Blue Marble image from NASA.

In [5]:
fig, ax = plt.subplots(figsize=(10, 10))
m = Basemap(projection='ortho', lat_0=45, lon_0=0, resolution='l', ax=ax)
m.etopo()
# draw borders only
m.drawcountries()
m.drawmeridians(np.arange(0,360,30))
m.drawparallels(np.arange(-90,90,30))
plt.show()

C:\Anaconda3\envs\interpies_test\lib\site-packages\mpl_toolkits\basemap\__init__.py:1711: MatplotlibDeprecationWarning: The axesPatch function was deprecated in version 2.1. Use Axes.patch instead.
if limb is not ax.axesPatch: