Folium
Folium is a Python library that builds on the data wrangling strengths of the Python ecosystem and the mapping strengths of the Leaflet.js library. It allows users to create interactive maps and geospatial visualizations that can be shared as standalone HTML files or integrated into web applications. The current version is 0.20.0, and it maintains an active release cadence with frequent updates and patch releases.
Warnings
- breaking Python 3.8 support was dropped in Folium versions 0.18.0 and 0.19.0. Users on Python 3.8 or older should upgrade their Python environment to at least 3.9 before upgrading Folium.
- deprecated The `Map.choropleth` method was deprecated and subsequently removed. Direct usage of `folium.Choropleth` class is required.
- deprecated Several Stamen tilesets (e.g., 'Stamen Toner', 'Stamen Terrain', 'Stamen Watercolor') were removed in v0.15.0 due to upstream changes or deprecations.
- gotcha When using Folium in Jupyter notebooks or similar environments, maps may not render if the notebook is not 'trusted' or if the map object is not the last expression in the cell. If a map doesn't appear, ensure the notebook is trusted and the map object `m` is the last line of the cell.
Install
-
pip install folium
Imports
- Map
import folium m = folium.Map(...)
- Marker
import folium folium.Marker(...).add_to(m)
- Choropleth
import folium folium.Choropleth(...).add_to(m)
- MarkerCluster
from folium.plugins import MarkerCluster
Quickstart
import folium
# Create a map centered at a specific location with a zoom level
m = folium.Map(location=[40.7128, -74.0060], zoom_start=12)
# Add a marker
folium.Marker(
location=[40.7128, -74.0060],
popup="<b>New York City</b>",
tooltip="Click for info"
).add_to(m)
# Save the map to an HTML file
m.save("folium_map.html")
# Display the map (useful in Jupyter notebooks, otherwise open the HTML file)
# m