Monday, 14 July 2025

πŸ—Ί️ Visualizing Geographic Data in Python with Folium

 


When it comes to visualizing geospatial data in Python, few libraries are as powerful and easy to use as Folium. Built on top of Leaflet.js, Folium makes it simple to create interactive maps without needing deep front-end knowledge.

In this post, we’ll explore how to use Folium to:

  • Create a base map

  • Add markers and popups

  • Visualize data with circles and choropleths

  • Save your map as an HTML file

Books: Python for Geography & Geospatial Analysis

Let’s dive in! 🐍


πŸ”§ Installation

First, install the library:

pip install folium

🌍 Creating Your First Map

Let’s create a simple map centered on a specific location (e.g., India):

import folium

# Center the map at a specific location (lat, lon)
map1 = folium.Map(location=[20.5937, 78.9629], zoom_start=5)

# Show the map in a Jupyter notebook
map1

This will display an interactive map right inside your notebook!


πŸ“ Adding Markers

You can easily place markers with popups:


folium.Marker(
    [28.6139, 77.2090],
    popup="New Delhi - Capital of India",
    icon=folium.Icon(color="blue")
).add_to(map1)

map1



cities = {
    "Mumbai": [19.0760, 72.8777],
    "Kolkata": [22.5726, 88.3639],
    "Chennai": [13.0827, 80.2707]
}

for city, coord in cities.items():
    folium.Marker(coord, popup=city).add_to(map1)

🎯 Adding Circle Markers

Highlight areas with radius-based circles:

folium.CircleMarker(
    location=[28.6139, 77.2090],
    radius=50,
    color='red',
    fill=True,
    fill_color='red',
    popup='Delhi Circle'
).add_to(map1)

πŸ—Ί️ Choropleth Maps

Visualizing data by region (e.g., population by state) is possible with choropleth maps:


# Requires a GeoJSON file (here we use a sample US one)
import pandas as pd

data = pd.DataFrame({
    'State': ['California', 'Texas', 'New York'],
    'Value': [100, 80, 60]
})

# Replace with your actual GeoJSON file path or URL
geo_data = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/us-states.json'

folium.Choropleth(
    geo_data=geo_data,
    name='choropleth',
    data=data,
    columns=['State', 'Value'],
    key_on='feature.id',
    fill_color='YlGn',
    legend_name='Example Data'
).add_to(map1)

πŸ’Ύ Saving Your Map

To share your map as a standalone HTML file:

map1.save("india_map.html")

Open india_map.html in your browser to explore the interactive map!


πŸš€ Why Use Folium?

  • Easy to integrate with Jupyter Notebooks

  • Built on Leaflet.js – beautiful and interactive by default

  • Supports tiles, overlays, popups, and GeoJSON

  • Great for data journalism, research, and education


πŸ“Œ Final Thoughts

With just a few lines of code, Folium allows you to transform your data into interactive maps. Whether you're building dashboards, displaying population data, or mapping delivery routes, Folium is a perfect starting point.

So next time you’re working with geographic data in Python — think Folium! 🌍

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (118) AI (152) Android (25) AngularJS (1) Api (6) Assembly Language (2) aws (27) Azure (8) BI (10) Books (251) Bootcamp (1) C (78) C# (12) C++ (83) Course (84) Coursera (298) Cybersecurity (28) Data Analysis (24) Data Analytics (16) data management (15) Data Science (217) Data Strucures (13) Deep Learning (68) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (17) Finance (9) flask (3) flutter (1) FPL (17) Generative AI (47) Git (6) Google (47) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (41) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (186) Meta (24) MICHIGAN (5) microsoft (9) Nvidia (8) Pandas (11) PHP (20) Projects (32) Python (1218) Python Coding Challenge (884) Python Quiz (342) Python Tips (5) Questions (2) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (45) Udemy (17) UX Research (1) web application (11) Web development (7) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)