Folium is a powerful Python library that helps you create several types of Leaflet maps. Folium builds on the data wrangling strengths of the Python ecosystem and the mapping strengths of the Leaflet.js library. Also, these maps are interactive so you can zoom into any region of interest despite the initial zoom level.
import folium
print('Folium imported.')
Folium imported.
World Map
Generate a World Map.
world_map = folium.Map()
world_map
Map of India
All locations on a map are defined by their respective latitude and longitude values. So you can create a map and pass in a center of Latitude and Longitude values of [0,0]. For a defined center, you can also define the initial zoom level into that location when the map is rendered. The higher the zoom level, the more the map is zoomed into the center.
Let’s create a map centered around India.
india_map = folium.Map(location=[21.7679, 78.8718], zoom_start=5)
india_map
Let’s play with the zoom level and focus on the city of Mumbai.
mumbai_latitude = 19.0760
mumbai_longitude = 72.8777
mumbai_map = folium.Map(location=[mumbai_latitude, mumbai_longitude], zoom_start=11)
mumbai_map
Let’s zoom in further to the Gateway of India.
mumbai_map = folium.Map(location=[18.9220, 72.8347], zoom_start=17)
mumbai_map
Stamen Toner Map
These are high contrast, black and white maps that can be used for exploring coastal zones and river meanders.
Every 12 years, millions of people are drawn to a spiritual festival in India, the Maha Kumbh Mela, at a place called the Triveni Sangam. It’s the largest gathering of humanity on Earth: over a three-month period, an estimated 100 million people attended the most recent festival, in 2013. The Triveni Sangam, where the festival takes place, is the meeting place of three rivers: Ganga, Yamuna, and Saraswati. However, the third river, the Saraswati is a mythical river, which supposedly dried up many millennia ago. Nevertheless, the Triveni Sangam is to this day referred to as the meeting place of the three rivers. There is a belief that the Saraswati river flows underneath the surface.
Let’s create a Stamen Toner map of the area.
sangam_map = folium.Map(location=[25.4224, 81.8866], zoom_start=9, tiles='Stamen Toner')
sangam_map
Stamen Terrain Maps
These are maps that feature hill shading and natural vegetation colors. They showcase advanced labeling and linework generalization of dual-carriageway roads.
Jammu and Kashmir, a union territory of India, is one of the most beautiful places in the world consisting of mountain rnages, valleys and rivers. Let’s explore the terrain in the area.
kashmir_map = folium.Map(location=[33.7782, 76.5762], zoom_start=8, tiles='Stamen Terrain')
kashmir_map