ComeçarComece de graça

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.

Este exercício faz parte do curso

Working with Geospatial Data in Python

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Load the restaurants dataset
restaurants = geopandas.read_file("paris_restaurants.geosjon")

# Take a subset of the African restaurants
african_restaurants = ____

# Make a multi-layered plot
fig, ax = plt.subplots(figsize=(10, 10))
restaurants.____
african_restaurants.____
# Remove the box, ticks and labels
ax.____
plt.show()
Editar e executar o código