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.
Este exercício faz parte do curso
Working with Geospatial Data in Python
Instruções do exercício
- 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 theax
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.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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()