Hands-on Tutorial On Folium, Python Library For Geographical Data Visualization

In this article, we will explore Folium, a python library which is used to create different types of geographical data visualizations. We will try and create different types of maps and markers on maps.
Folium- Geographical Data Visualization

Geographical data is defined as the data which is relative to a certain location. As it is a location on earth we can represent it on a map. Representing geographical data on a map is easy using python libraries.  

Python provides different open-source libraries for geographical data visualization. These libraries are easy to use and create highly interactive and visually appealing maps. 

In this article, we will explore Folium, a python library which is used to create different types of geographical data visualizations. We will try and create different types of maps and markers on maps. 

THE BELAMY

Sign up for your weekly dose of what's up in emerging technology.

Implementation: 

We will start by installing Folium using pip install folium.

  1. Importing required libraries

We will import folium which contains all the functions that are required for geographical data visualization.

import folium

  1. Exploring Folium

We will start exploring folium by creating a world map in just one line of code.

world_map = folium.Map()

world_map

World Map using Folium

Similarly, we can create maps for different locations by just passing the Longitude and Latitude of the respective location. Let us plot the Bangalore Map using folium. You can google the Latitude and Longitude of your respective location.

  • Creating a map of Bangalore

bang_map = folium.Map(location=[12.9716, 77.5946], zoom_start=12)

bang_map

Bangalore Map using Folium
  • Creating a world map with Markers

Folium allows us to create a marker on the map for a particular location by using the marker function. Let us explore it by marking capitals of some countries on the world map.

cap = folium.Map(zoom_start=6)

folium.Marker(location=[28.7041, 77.1025 ], popup='Delhi').add_to(cap)

folium.Marker(location=[39.9042, 116.4074], popup='Beijing').add_to(cap)

folium.Marker(location=[55.7558, 37.6173], popup='Moscow').add_to(cap)

  • Different Styles of Map

Folium supports different types of map formats that clearly display different attributes like Roads, Rivers, etc. Let us explore different types of maps using coordinates of India.

First, we will explore the Stamen Toner map which is a high contrast Black & White map which helps in visualizing the river meanders and coastal zones clearly and then Stamen Terrain which shows hill shading and natural vegetation colors.

  1. Stamen Toner

india_map =folium.Map(location=[20.5937, 78.9629 ],zoom_start=5,   tiles='Stamen Toner')

india_map

India Map in Stamen Toner
  1. Stamen Terrain

india_map =folium.Map(location=[20.5937, 78.9629 ], zoom_start=5, tiles='Stamen Terrain')

india_map

You can see in the output images how clearly these tiles work to show different attributes of the geographical area. Similarly, you can explore many more tile styles that are there in folium.

Folium allows us to create interactive maps in just a single line of code and of different types and locations. You can zoom-in or zoom-out of the maps to get a clear picture of the location and the surroundings.

Conclusion:

In this article, we explored the basics of folium, how we can create different maps with different styles in just a single line of code. We saw how we can create a marker on the map to notify the respective location. We saw how different parameters can change the view and style of the map. 

We saw that folium is a powerful library that is used to create highly interactive leaflet maps with different views and styles

More Great AIM Stories

Himanshu Sharma
An aspiring Data Scientist currently Pursuing MBA in Applied Data Science, with an Interest in the financial markets. I have experience in Data Analytics, Data Visualization, Machine Learning, Creating Dashboards and Writing articles related to Data Science.

Our Upcoming Events

Conference, in-person (Bangalore)
Machine Learning Developers Summit (MLDS) 2023
19-20th Jan, 2023

Conference, in-person (Bangalore)
Rising 2023 | Women in Tech Conference
16-17th Mar, 2023

Conference, in-person (Bangalore)
Data Engineering Summit (DES) 2023
27-28th Apr, 2023

Conference, in-person (Bangalore)
MachineCon 2023
23rd Jun, 2023

Conference, in-person (Bangalore)
Cypher 2023
20-22nd Sep, 2023

3 Ways to Join our Community

Whatsapp group

Discover special offers, top stories, upcoming events, and more.

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Subscribe to our newsletter

Get the latest updates from AIM