Basemap

Basemap is among the most popular Matplotlib-based plotting toolkits to plot over world maps. It is a handy way to show any geographical location.

To install Basemap, do this:

  1. Unpack in $Python3_dir/site-packages/mpl_toolkits
  2. Enter the Basemap installation directory: cd $basemap_dir
  3. Enter the geos directory in the Basemap directory: cd $basemap/geos-3.3.3
  4. Install the GEOS library via ./configure, make, and make install
  5. Install PyProj (refer to the following tip)
  6. Return to the Basemap installation directory and run python3 setup.py install
  7. Set the environment variable PROJ_DIR=$pyproj_dir/lib/pyproj/data
Basemap requires PyProj as a dependency, where there are recurrent reports of installation failures. We recommend installing  from GitHub with prior installation of the Cython dependency.
  1. Clone the PyProj GitHub repository from https://github.com/jswhit/pyproj into the Python site packages directory
  2. Install the Cython dependency with pip install --user cython
  3. Enter the PyProj directory and install using python3 setup.py install
For Windows users, it could be easier to install via Anaconda with the command prompt conda install -c conda-forge geopandas.

As a brief introduction, we will show how to draw our beautiful Earth with shaded terrain with the following code snippet:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

# Initialize a Basemap object
# Use orthogonal spherical projection
# Adjust the focus by setting the latitude and longitude
map = Basemap(projection='ortho', lat_0=20, lon_0=80)

# To shade terrain by relief. This step may take some time.
map.shadedrelief()

# Draw the country boundaries in white
map.drawcountries(color='white')
plt.show()

Here is how the plot looks:

Besides showing the earth as a sphere with orthogonal projection as shown in the preceding figure, we can also set projection='cyl' to use the Miller Cylindrical projection for a flat rectangular illustration.

Basemap provides plenty map drawing functions, such as drawing coastlines and plotting data over maps with hexbin or streamplot. Their details can be found in the official tutorials at http://basemaptutorial.readthedocs.io. As in-depth geographical analysis is beyond the scope of this book, we will leave a more specific exploration of its usage as an exercise for interested readers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.201.106