Choropleth Maps

Introduction

Choropleth maps hold a significant place in the geospatial analysis and visualization domain. They are thematic maps in which areas are shaded or patterned according to the value of an associated variable being displayed on the map. This variable can be categorical, such as the major ethnic group in that region, or continuous measurements, such as population density or per-capita income. This results in a powerful visualization that can instantly communicate complex data in an intuitive geographical format.

For example, by color-coding regions based on the proportion of votes for different candidates, a choropleth map can instantly convey which areas are supporting which candidates. Similarly, a public health researcher could use a choropleth map to understand the distribution of a particular health condition, like asthma or diabetes, across different neighborhoods or states.

In the next section, we are going to cover some examples of choropleth maps made with GeoPandas and their many styling options.

Categorical choropleth with legends

For this example, we are going to color the Brazilian states according to their geopolitical regions. To create a choropleth map we must pass the name of the column containing the variable to be used as a reference for plotting (line 7). The categorical argument of the plot() method is used to control the color map being used for mapping (line 8). This should be True for nonnumerical values and False otherwise.

To include a legend, we can set legend=True in the plot function (line 9), and pass style options through the legend_kwds argument (line 10). Note that legend_kwds must be a dictionary containing styling options accepted by Matplotlib. Additionally, we can also specify the Matplotlib color map to be used (cmap argument in line 11).

Get hands-on with 1400+ tech skills courses.