Folium heatmap legend


  • Visualising Geospatial data with Python using Folium
  • They are important because they can provide information for geographic location, they look beautiful and grab attention in a presentation.

    Several different libraries can be used to do that. In this tutorial, I will use folium. What is a choropleth map? Here is the definition from Wikipedia: Choropleth maps provide an easy way to visualize how a measurement varies across a geographic area or show the level of variability within a region.

    A heat map or isarithmic map is similar but does not use a priori geographic areas. They are the most common type of thematic map because published statistical data from government or other sources is generally aggregated into well-known geographic units, such as countries, states, provinces, and counties, and thus they are relatively easy to create using GIS , spreadsheets , or other software tools.

    In simple and easy words, choropleth maps are the maps that show the information by geolocation using color on the map. See some of the pictures below to get more understanding. Data Preparation Data preparation is an important and common task for all data scientists.

    The dataset I used here is reasonably nice and clean. But for this visualization, I still need to work on it a bit. I encourage you to run the code by yourself. This dataset contains how many immigrants came to Canada from the different countries of the world from to We need the name of the country and the years.

    Drop some unnecessary columns from the dataset. It gives the total number of immigrants for each country. Remember that setting this axis as 1 is important. It says that the sum operation should be across columns. Otherwise, it will do the sum across rows and we will end up getting the total number of immigrants per year instead of per country.

    Basic Choropleth Map I am going to show, how to develop a choropleth map step by step here. Import folium. If you do not have folium, install it by running this command in your anaconda prompt: conda install -c conda-forge folium Import folium now and generate a world map.

    But it also requires geo data that contains coordinates of each country. Download the geo data from this link. I already downloaded and put it in the same folder as the notebook I used for this tutorial. I just need to read that file now. That JSON file is too big. I think these are self-explanatory. Here is the code for our first choropleth map: world. You can navigate around using the mouse.

    Also, it changes the color with intensity. The darker the color, the more immigrants came from that country to Canada. But black means there is no data available or there were no immigrants. Add Tiles This map may look a bit plane. We can make it more interesting by using a few tiles which will give us options to change the tiles based on the requirement. In the end, we will also include the LayerControl method to get the option of altering the layers.

    TileLayer tile. If you click on that you will get the list of tiles. You will be able to change the tiles style there. I find this option very cool! Add Informative Label Finally, I want to show you another useful and interesting option. That is to use an informative label. We cannot expect everyone to know the name of the country by looking at the map.

    It will be useful to have the label of the country on the map. We will make it interesting. First, we need to make the world map as usual. Add all the parameters to it and save in a variable. Here is the complete code. The same way you can put the cursor in any place of the map get the name of the place. Conclusion I wanted to show how to develop an interactive choropleth map, style it, and add informative labels to it. I hope it was helpful.

    Also, since we are dealing with geospatial maps, we also need the country coordinates for plotting. Download the file from here. The file can also be downloaded from my github repo. It contains over a thousand annual indicators of economic development from about countries around the world from to Few of the Indicators are: 1. Adolescent fertility rate births per 1, women 2. CO2 emissions metric tons per capita 3.

    Merchandise exports by the reporting economy 4. Time required to build a warehouse days 5. Life expectancy at birth, female years Getting started Jump over to the Jupyter Notebooks and import the required libraries. Make sure to create the jupyter notebook in the same folder as data for ease. It seems that the indicators dataset have different indicators for different countries with the year and value of the indicator.

    Life expectancy at birth, female years appears to be good indicator for investigation. We are just choosing the year at random. This allows us to quickly visualize data combinations map. This it the tie that we need to set up in our data. Our country code in the data frame should match the feature ID in the json object.

    Next, we specify some of the aesthetics, like the color scheme, the opacity and then we label the legend. The output of this plot is going to be saved as a html file which is actually interactive. Code: map. Notice first the dark colors imply higher life expectancy for females.

    Clearly US and majority of Europe have a higher life expectancy for females. So, this is an example of how to do geographic overlays. It is also as an example of how to use additional visualization libraries and how they can be powerful depending on our visualization needs.

    This was a pretty simple first step into the world of choropleth maps using Pandas dataframes and Folium. You can explore more about folium and the interactiveness it provides at the official documentation page. To see the actual interactiveness of the map, visit the Github repo.

    They are the most common type of thematic map because published statistical data from government or other sources is generally aggregated into well-known geographic units, such as countries, states, provinces, and counties, and thus they are relatively easy to create using GISspreadsheetsor other software tools.

    In simple and easy words, choropleth maps are the maps that show the information by geolocation using color on the map. See some of the pictures below to get more understanding.

    Data Preparation Data preparation is an important and common task for all data scientists. The dataset I used here is reasonably nice and clean. But for this visualization, I still need to work on it a bit. I encourage you to run the code by yourself.

    Visualising Geospatial data with Python using Folium

    This dataset contains how many immigrants came to Canada from the different countries of the world from to We need the name of the country and the years. Drop some unnecessary columns from the dataset. It gives the total number of immigrants for each country. Remember that setting this axis as 1 is important.

    It says that the sum operation should be across columns. Otherwise, it will do the sum across rows and we will end up getting the total number of immigrants per year instead of per country. Basic Choropleth Map I am going to show, how to develop a choropleth map step by step here.

    Import folium.

    If you do not have folium, install it by running this command in your anaconda prompt: conda install -c conda-forge folium Import folium now and generate a world map. This allows us to quickly visualize data combinations map. This it the tie that we need to set up in our data. Our country code in the data frame should match the feature ID in the json object.

    Next, we specify some of the aesthetics, like the color scheme, the opacity and then we label the legend. The output of this plot is going to be saved as a html file which is actually interactive. Code: map. Notice first the dark colors imply higher life expectancy for females. Clearly US and majority of Europe have a higher life expectancy for females. So, this is an example of how to do geographic overlays.

    Possible options include clearing the geometry resetting it to nullcopying the geometry as WKT or GeoJSON, or pasting geometry into the feature from a WKT string making it super easy to copy the geometry between features. This could also be extended in future to start incorporating the editing capabilities current possible through the Plain Geometry Editor plugin. Custom legend shapes anyone? Improving the heatmap plugin: The current heatmap plugin needs some love.

    The code and UI could do with a big refresh. The major limitation with the calculator is that it currently only supports functions with at most two parameters. Of course, this list is just a start. Just drop me an email at [email protected] to discuss.

    More on that shortly. Introducing QGIS live layer effects! April 8, nyalldawson.


    Folium heatmap legend