Putting It All Together: World Ecological Footprint
00:11 By the end of this lesson, you’ll roughly recreate this world map using Folium. This choropleth displays the ecological footprint of countries of the world, where the numerical values represent global hectares per capita, or gha.
00:43 In order to make this map in Folium, you’ll create a base map for the world and select your web tiles. You’ll update the starting location and zoom level for an appropriate view of the world. You’ll add boundaries for each country through GeoJSON data, and then you’ll add a choropleth layer based on ecological footprint data.
Finally, you’ll customize the map to make it look more like the original by updating the color scheme, binning, and so on. Let’s get started. Recall that you can make a base map in Folium with
01:49 You now have a solid base map that you can build your choropleth on. Next, you’ll need a GeoJSON file that dictates the countries’ boundaries. This time, instead of linking up with a GeoJSON file from your computer, let’s use a URL that provides this data for you.
The Natural Earth Project provides the type of data that you’ll need through its
geojson.xyz service. For this map, you can use the
admin 0 countries resource since it offers relatively high-quality borders for political countries of the world.
Use pandas to read that CSV and store its contents as a pandas DataFrame called
eco_footprints. Here are the first five rows. Each row is a country or region with various ecological measurements.
03:47 When adding this dataset to your map, you’ll need to link up the country names with some property in your GeoJSON. So let’s look at the GeoJSON data by visiting the political countries URL in our browser. There are several properties here for each country, including its postal code and an estimate for its population.
To add a choropleth layer, use
folium.Choropleth, then supply the geodata, which will be the political countries URL in this case, as well as the data that you want to display. Here that’s the
The data columns of interest are the
"Country/region", which will contain the country names, and the
"Ecological footprint" column, which has the choropleth data. Finally, you want to match up the names in the
"Country/region" column with the
name property of your GeoJSON, so
05:10 Excellent. You now have an ecological footprint choropleth for countries of the world. The map doesn’t quite look like the example you want to re-create, however, so let’s do some styling. For starters, you can update the color scheme.
These are areas that are either missing data points or are missing matching names. The dark colors tend to distract from the other countries that are filled in, so let’s also set
nan_fill_color to be
"white" so that those areas dominate less.
This is already looking much better, but you can also update the opacity to make the countries less transparent, while making the borders of each country more so. Update the property
fill_opacity to be
line_opacity to be
06:33 One of the bigger updates that you likely already noticed involves the binning for each color. The example world map features custom cutpoints, with any country over 8 gha displayed in the darkest red color, so let’s make our own bins for this choropleth. To do so, you’ll need to know the minimum and maximum values.
Global hectare won’t be negative, so you can use
0 for the start of the smallest bin, and for the end of the upmost bin, just create a Python variable to represent the maximum of the ecological footprint column.
As a final customization, you can also title your color bar so that your users know what the values of your map represent. Let’s update
legend_name to be
"Ecological Footprint per Capita (gha)". Excellent.
08:05 You created a Folium map for ecological footprint data of the world in this lesson. Coming up next, you’ll conclude this course by reviewing Folium and learning how it compares to other Python mapping libraries.
Become a Member to join the conversation.