1. Learn
  2. /
  3. Courses
  4. /
  5. Working with Geospatial Data in Python

Exercise

Plotting multiple layers

Another typical pandas functionality is filtering a dataframe: taking a subset of the rows based on a condition (which generates a boolean mask).

In this exercise, we will take the subset of all African restaurants, and then make a multi-layered plot. In such a plot, we combine the visualization of several GeoDataFrames on a single figure. To add one layer, we can use the ax keyword of the plot() method of a GeoDataFrame to pass it a matplotlib axes object.

The restaurants data is already loaded as the restaurants GeoDataFrame. GeoPandas is imported as geopandas and matplotlib.pyplot as plt.

Instructions

100 XP
  • Select a subset of all rows where the type is 'African restaurant'. Call this subset african_restaurants.
  • Make a plot of all restaurants and use a uniform grey color. Remember to pass a matplotlib axes object to the plot() method.
  • Add a second layer of only the African restaurants in red. For the typical colors, you can use English names such as 'red' and 'grey'.
  • Remove the box using the set_axis_off() method on the matplotlib axes object.