Get startedGet started for free

Compare classification algorithms

In this final exercise, you will build a multi map figure that will allow you to compare the two approaches to map variables we have seen.

You will rely on standard matplotlib patterns to build a figure with two subplots (Axes axes[0] and axes[1]) and display in each of them, respectively, an equal interval and quantile based choropleth. Once created, compare them visually to explore the differences that the classification algorithm can have on the final result.

This exercise comes with a GeoDataFrame object loaded under the name district_trees that includes the variable n_trees_per_area, measuring tree density by district.

This exercise is part of the course

Working with Geospatial Data in Python

View Course

Exercise instructions

  • Make a choropleth for the 'n_trees_per_area' column using the equal interval classification scheme on the first subplot (axes[0]). Remember that you can pass the matplotlib axes object to the ax keyword.
  • Do the same for the quantile classification scheme on the second subplot (axes[1]). As in the previous plot, set the title and remove the box and axis labels to create a cleaner figure.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Set up figure and subplots
fig, axes = plt.subplots(nrows=2)

# Plot equal interval map
districts_trees.plot(____, ____, k=5, legend=True, ax=____)
axes[0].set_title('Equal Interval')
axes[0].set_axis_off()

# Plot quantiles map
districts_trees.plot(____, ____, k=5, legend=True, ax=____)
____.set_title('Quantiles')
____.set_axis_off()

# Display maps
plt.show()
Edit and Run Code