top of page
GeoWGS84AI_Logo_edited.jpg

The Ultimate Guide to Folium for Geospatial Visualization in Python

  • 5 minutes ago
  • 3 min read

Location-based mapping is a key factor in the evolution of the modern world's data science, location intelligence, logistics optimization, urban planning, environmental monitoring, and analytics. Companies are using interactive maps as a tool for better understanding relationships, discovering patterns, and making decisions based on data.


Of all the many available Python libraries for running geographic data visualizations, Folium is one of the best, most versatile, and user-friendly. Folium is built on the Leaflet.js JavaScript mapping library, allowing developers to quickly create highly interactive web maps using the Python programming language.


Folium for Geospatial Visualization in Python
Folium for Geospatial Visualization in Python

What is Folium?


Folium is a Python library that is open-source, allowing you to connect how you process data in Python to how you can visually represent that data using Leaflet.js.


This allows developers of Folium to:


  • Build interactive maps

  • Plot spatial data

  • Add custom markers

  • Visualize geoJSON and shape files.

  • Create choropleth maps

  • Develop heatmaps

  • Create location-based dashboards


Folium produces HTML-based maps that allow users to perform:


  • Zooming

  • Panning

  • Toggling between layers

  • Using interactive pop-ups

  • Viewing dynamic tooltips


Embeddable into websites, dashboards, Jupyter notebooks, Streamlit applications, and data portals.


Why Use Folium?


Key Advantages


Lightweight


Folium uses small HTML files, along with browser rendering of leaflets with JavaScript code.


Easy Learning Curve


Using Python, users with some programming knowledge can create advanced maps using little code.


Nice Ecosystem


Supports the following file types:


  • geoJSON

  • TopoJSON

  • WMS Layers

  • Raster Tiles

  • heatmaps

  • Marker clusters


Web Ready


Maps can be saved to HTML format and deployed anywhere on the web.


Installing Folium


Install Folium using pip:

pip install folium

For geospatial workflows:

pip install geopandas shapely pyproj

Verify installation:

import folium

print(folium.__version__)

Creating Your First Interactive Map


The simplest map requires only latitude and longitude coordinates.

import folium

m = folium.Map(
    location=[40.7128, -74.0060],
    zoom_start=12
)

m

Understanding Tile Layers


Tile layers define the map's visual appearance.

folium.Map(
    location=[40.7128, -74.0060],
    zoom_start=12,
    tiles="CartoDB Positron."
)

Example:

folium.Map(
    location=[51.5074, -0.1278],
    tiles="Stamen Terrain",
    zoom_start=10
)

Adding Markers


Markers are the foundation of location visualization.

import folium

m = folium.Map(location=[37.7749, -122.4194])

folium.Marker(
    location=[37.7749, -122.4194],
    popup="San Francisco",
    tooltip="Click for details."
).add_to(m)

m

Custom Icons


Customize marker appearance using Font Awesome icons.

folium.Marker(
    location=[37.7749, -122.4194],
    icon=folium.Icon(
        color="red",
        icon="info-sign"
    )
).add_to(m)

Supported colors:

[
 "red",
 "blue",
 "green",
 "purple",
 "orange",
 "darkred",
 "lightgray"
]

Interactive Popups


Popups can contain rich HTML content.

html = """
<h3>Data Center</h3>
<p>Status: Active</p>
<p>Capacity: 5 MW</p>
"""

folium.Marker(
    location=[37.77, -122.42],
    popup=folium.Popup(html, max_width=300)
).add_to(m)

Circle Markers


Circle markers are ideal for visualizing quantitative values.

folium.CircleMarker(
    location=[40.7128, -74.0060],
    radius=12,
    color="blue",
    fill=True,
    fill_opacity=0.7
).add_to(m)

Example for population scaling:

folium.CircleMarker(
    location=[lat, lon],
    radius=population / 100000,
    fill=True
)

Drawing Geographic Shapes


Circles

folium.Circle(
    location=[40.7128, -74.0060],
    radius=5000,
    color="green",
    fill=True
).add_to(m)

Polylines


Useful for routes and trajectories.

folium.PolyLine(
    [
        [40.7128, -74.0060],
        [41.8781, -87.6298]
    ],
    color="red",
    weight=4
).add_to(m)

Polygons

folium.Polygon(
    locations=[
        [40.7, -74.0],
        [40.8, -74.1],
        [40.9, -74.0]
    ],
    color="blue",
    fill=True
).add_to(m)

Working with GeoJSON Data


GeoJSON is the industry standard format for geospatial data exchange.

import folium

m = folium.Map(location=[20, 0], zoom_start=2)

folium.GeoJson(
    "countries.geojson"
).add_to(m)

m

Styling GeoJSON Layers

folium.GeoJson(
    geojson_data,
    style_function=lambda feature: {
        "fillColor": "blue",
        "color": "black",
        "weight": 1,
        "fillOpacity": 0.6
    }
).add_to(m)

Creating Choropleth Maps


Choropleth maps visualize geographic regions using color gradients.

Common use cases:

  • Population density

  • Election results

  • GDP by country

  • Disease prevalence

  • Sales by state


Example:

folium.Choropleth(
    geo_data=" states.geojson",
    data=df,
    columns=["state", "sales"],
    key_on=" feature.properties.name",
    fill_color="YlGnBu",
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name="Sales"
).add_to(m)

Heatmap Visualization


Heatmaps reveal spatial density patterns.

Install plugins:

from folium. plugins import HeatMap

Example:

heat_data = [
    [40.7128, -74.0060],
    [40.7138, -74.0050],
    [40.7148, -74.0040]
]

HeatMap(heat_data).add_to(m)

Weighted heatmap:

HeatMap(
    [
        [lat, lon, weight]
    ]
)

Marker Clustering


Thousands of markers can overwhelm browsers.

Marker clustering solves this problem.

from folium. plugins import MarkerCluster

cluster = MarkerCluster().add_to(m)

for _, row in df.iterrows():
    folium.Marker(
        [row.lat, row.lon]
    ).add_to(cluster)

Benefits:

  • Faster rendering

  • Better user experience

  • Reduced visual clutter


Integrating Folium with GeoPandas


GeoPandas and Folium form a powerful geospatial stack.

import geopandas as gpd

gdf = gpd.read_file("roads.shp")

Convert to GeoJSON:

folium.GeoJson(
    gdf.to_json()
).add_to(m)

Visualize directly:

folium.GeoJson(
    gdf,
    tooltip=folium.GeoJsonTooltip(
        fields=["name"]
    )
).add_to(m)

Folium is a Python library for geospatial visualization that is widely recognized as one of the most effective libraries available. It combines the Python ecosystem for data processing with Leaflet.js interactivity to allow developers to create sophisticated location visualizations with very little code.


Folium provides the flexibility, performance, and ease of use required for modern geospatial analytics, whether creating choropleth maps, heatmaps, route visualisations, geospatial dashboards, or large-scale location intelligence systems.


Mastering Folium will give data scientists, GIS professionals, software engineers, and business analysts a valuable tool that unlocks new opportunities for turning geographic data into actionable insights.


To learn more about Folium and its geospatial capabilities, click here.


For more information or any questions regarding Folium, please don't hesitate to contact us at


USA (HQ): (720) 702–4849


(A GeoWGS84 Corp Company)



 
 
 
bottom of page