Session Ready
Exercise

Adding a background map

A plot with just some points can be hard to interpret without any spatial context. Therefore, in this exercise we will learn how to add a background map.

We are going to make use of the contextily package. The add_basemap() function of this package makes it easy to add a background web map to our plot. We begin by plotting our data first, and then pass the matplotlib axes object to the add_basemap() function. contextily will then download the web tiles needed for the geographical extent of your plot.

To set the size of the plotted points, we can use the markersize keyword of the plot() method.

Pandas has been imported as pd and matplotlib's pyplot functionality as plt.

Instructions
100 XP
  • Import contextily.
  • Re-do the figure of the previous exercise: make a plot of all the points in restaurant.
  • Set the marker size equal to 1 to reduce the size of the points.
  • Use the add_basemap() function of contextily to add a background map: the first argument is the matplotlib axes object ax.