Mapping#

Up to this point, we have been working with data plotted on a 2D cartesian coordinate system, with x and y axes. For our purposes, it’s most useful to think of maps in the same way–as data plotted on a coordinate system. Except for maps, that coordinate system is typically some type of latitude or longitude based projection, and the data to be plotted includes explicit location information (rather than a numerical or categorical field that can be mapped to an axis).

This chapter provides an introduction to geospatial data, including structures and formats, with a focus on Python programming workflows. It also covers static visualization workflows with GeoPandas and interactive visualization workflows with plotly.

Acknowledgements#

The author consulted the following resources when developing this chapter:

Chapter Contents#

Data#

We’ll be working with a few different datasets in this chapter.

Sample datasets from the plotly library. Code to load these datasets is included.

  • 2014 U.S. Cities Population

  • Gapminder Data

  • NYC Uber Rides

  • U.S. Unemployment Data

  • GeoJSON U.S. County Boundaries

Mapbox Access Token#

Later in this chapter, we’ll be working with features of the Mapbox API that require an access token.

Sign up for a free Mapbox account:

Once you have signed up and logged in, click Token in the top level menu (between Dashboard and Statistics).

Click the Create a token button to create a new access token:

Choose a descriptive name for your token (“Elements of Computing” works fine). The default settings for which boxes are checked/unchecked are fine.

Click the Create token button at the bottom of the page.

Save this token value (string of numbers and letters) for later in the chapter.

Application#

Click here for a Jupyter Notebook template for this chapter’s application problems.