Brazilian States Choropleth Map with Python
Hello there,
I decided to create this post because I didn't really find an easy solution for this type of plot. The majority of examples for choropleth map plots are based on United States only.
So here's a step by step of how to create your own choropleth map using the states of Brazil. For the example, I use the amount of confirmed cases of COVID-19 up to date. The data was taken from the Health Government portal updated until April 2nd.
STEP 01
Load the file “bcim_2016_21_11_2018.gpkg”. This file contains a series of relevant layers to create this type of plots.
Where can I find this file? On IBGE website https://www.ibge.gov.br/.
After accessing the website, follow the steps below:
Geociências -> Downloads -> cartas_e_mapas -> bcim -> versao2016 — geopackage
This file was inserted on my work directory. This was I can use the function read_file from geopandas package to read it's content.
In the following lines of code, I'll import the downloaded file and use the parameter lim_unidade_federacao_a to create the initial DataFrame with the information needed for the plot.
STEP 02
A choropleth map has the purpose of inform the density of a given data thru the colors. So I'll need to choose some data to represent these colors.
I choose the information of the amount of confirmed cases from COVID-19 in Brazil. This data is ready to use in an Excel file called corona_cases and located in my working directory.
Now, I'll import this data into a pandas DataFrame object.
STEP 03
Now I need to join the amount of cases with the Lat/Long of each State. So I'll use the merge functions to help me with that.
STEP 04
Now I have everything I need to create my plot. So all I have to do is use the plot() function with the given parameters to generate the plot.
In this plot, we can easily see that the worst situation is in São Paulo, followed by Rio de Janeiro.
Of course there is many other parameters that will make your plot prettier. The ones I used are the basics so you can be able to create the plot structure. More infos about geopandas package can be found in the oficial documentation https://geopandas.org/.
Rodrigo Deboni Dutcosky.