Introduction
If you have ever tried to explain where something happened using a spreadsheet, you already know the problem. Rows and columns do not show clusters, gaps, routes, or regional patterns the way a map does, and that is where python folium becomes useful.
Certified Ethical Hacker (CEH) v13
Learn essential ethical hacking skills to identify vulnerabilities, strengthen security measures, and protect organizations from cyber threats effectively
Get this course on Udemy at the lowest price →Python Folium is a Python library for building interactive, leaflet-based web maps with minimal setup. It is practical for dashboards, reports, storytelling, location analysis, and data exploration because users can zoom, pan, click markers, and switch layers without leaving the browser.
Folium can create markers, choropleths, heatmaps, clustered points, and layered maps. That makes it a good fit for everything from store locators to incident analysis, and it pairs well with skills covered in the CEH v13 course when you need to visualize asset locations, exposure, or attack patterns.
Quick Answer
Python Folium is a library for building interactive Leaflet-based maps in Python with very little setup. As of May 2026, it is commonly used to create marker maps, choropleths, heatmaps, and layer controls, then export the result as HTML for sharing in browsers, reports, and dashboards.
Quick Procedure
- Install Folium with pip.
- Import Folium in Python or Jupyter.
- Create a Map object with latitude, longitude, and zoom.
- Add markers, popups, or data layers.
- Save the map as HTML.
- Open the HTML file in a browser and verify the output.
| Primary Library | Python Folium as of May 2026 |
|---|---|
| Rendering Engine | Leaflet.js as of May 2026 |
| Typical Output | Interactive HTML map as of May 2026 |
| Best Workflows | Jupyter Notebook, JupyterLab, or Python script as of May 2026 |
| Common Map Types | Markers, clustered points, choropleths, GeoJSON overlays, heatmaps as of May 2026 |
| Installation Method | pip install folium as of May 2026 |
| Sharing Format | Standalone HTML for browser viewing as of May 2026 |
Getting Started With Folium
Python Folium is a library that wraps the JavaScript mapping engine Leaflet.js and exposes it through Python objects. The value is simple: you write Python, but you end up with a fully interactive web map in HTML.
Installation is straightforward. In a terminal or notebook cell, run pip install folium. If you are working in a managed environment, make sure the package installs into the same interpreter your notebook or script uses.
Recommended Working Environment
Folium works well in Jupyter Notebook, JupyterLab, or a standard Python IDE. Notebook users get instant visual feedback, while script users usually save the map to HTML and open it in a browser.
A quick verification test looks like this:
import folium
m = folium.Map(location=[40.7128, -74.0060], zoom_start=12)
m
If the notebook renders a map centered on New York City, the installation is working. In a script, you would usually save the object with m.save("map.html") and open the file manually.
Folium is best understood as a Python front end for browser-based map generation, not as a GIS desktop replacement.
Note
Folium maps are typically saved as HTML files, which makes them easy to share, embed, and open offline as long as the referenced tile layers are reachable or cached by the browser.
For current implementation details, the official project page and Leaflet documentation are useful references. See the Folium documentation and Leaflet project site.
Understanding The Core Map Object
The foundation of every Folium map is folium.Map(). Map is the object that defines where the map starts, how large it appears, and which tile layer it uses as the basemap.
The most common parameters are location, zoom_start, tiles, width, and height. A location is a latitude and longitude pair, while zoom controls how much geographic detail the user sees at load time.
Common Parameters You Will Use First
- location sets the map center, such as
[51.5074, -0.1278]for London. - zoom_start controls zoom level; 10 to 13 is common for city views.
- tiles sets the basemap style, such as OpenStreetMap or CartoDB.
- width and height control the map size in pixels or percentages.
Centering a map on a city, region, or country is just a matter of choosing the right coordinates. For example, a street-level neighborhood view needs a higher zoom like 15 or 16, while a country-level dashboard usually starts near 5 or 6.
Tile choice matters more than many beginners expect. OpenStreetMap is simple and familiar, Stamen Terrain is useful for outdoor context, and CartoDB styles often improve contrast for dashboards and presentations.
| Basemap Style | Best Use |
|---|---|
| OpenStreetMap | General-purpose mapping with a clean default look |
| Stamen Terrain | Elevation, terrain, and outdoor context |
| CartoDB Positron | Light dashboard design with strong overlay contrast |
| CartoDB Dark Matter | Dark-themed visualizations and high-contrast point data |
For basemap choices and usage details, the most reliable source is the official Folium project documentation at Folium. If you need to understand the mapping behavior behind the scenes, the Leaflet reference is the source of truth.
Adding Markers And Popups
Marker is the basic point annotation you place on a map to show a location such as an office, event site, tourist attraction, or store. In Folium, markers become more useful when you attach popup and tooltip content to them.
A popup is the content that appears when the user clicks a marker. A tooltip appears on hover and is better for short labels when you want less friction and less clutter.
Single Marker Example
import folium
m = folium.Map(location=[37.7749, -122.4194], zoom_start=12)
folium.Marker(
location=[37.7749, -122.4194],
popup="San Francisco Office",
tooltip="Main office"
).add_to(m)
m.save("san_francisco_map.html")
For richer popups, you can include HTML, links, and formatting. That is useful when a map needs to show store hours, a report link, or a short incident summary.
Icon Customization
Marker icons can be changed for color, symbol, and visual emphasis. Folium supports icon types that work well for differentiating warehouse hubs, customer sites, emergency services, or attraction categories.
- Color helps separate categories quickly.
- Icon symbol can represent the function of the location.
- Font Awesome or Bootstrap-style icons can improve readability when used sparingly.
Example use case: a retail analyst may mark store locations with blue icons, distribution hubs with red icons, and planned sites with gray icons. That approach reduces the need to inspect every popup before understanding the map.
For background on icon rendering and map object behavior, consult the official Folium documentation at Folium.
Working With Multiple Locations
When your data has dozens or thousands of points, adding markers one by one becomes unmanageable. The better approach is to loop through a dataset, validate the coordinates, and create markers dynamically from a Jupyter notebook or script.
This workflow is common for restaurants, customer addresses, incidents, property listings, and field service locations. It also ties into the data wrangling mindset used in the CEH v13 course when you need to organize evidence or location-based indicators before presenting them clearly.
Looping Through Data
- Load your coordinates into a Pandas DataFrame.
- Check that latitude and longitude columns exist and are numeric.
- Filter out missing or invalid values before plotting.
- Iterate through each row and create a marker or custom layer.
- Save or render the finished map after the loop completes.
import pandas as pd
import folium
df = pd.DataFrame({
"name": ["Hub A", "Hub B", "Hub C"],
"lat": [34.0522, 34.0407, 34.0739],
"lon": [-118.2437, -118.2468, -118.2400]
})
m = folium.Map(location=[34.0522, -118.2437], zoom_start=11)
for _, row in df.iterrows():
folium.Marker(
location=[row["lat"], row["lon"]],
popup=row["name"]
).add_to(m)
m.save("multiple_locations.html")
Marker Clustering For Dense Data
Marker clustering groups nearby points into expandable clusters so the map stays readable when many points overlap. This is especially helpful for dense urban data such as restaurants, delivery stops, or security incidents.
Clustering also improves visual performance because the browser does less work drawing individual points at the same time. When using large datasets, this is often the difference between a usable map and a cluttered one.
Before plotting, always check for reversed coordinates. Latitude should be the north-south value, and longitude should be the east-west value; swapping them is one of the most common reasons maps land in the wrong place.
For data handling guidance, the Pandas documentation is the best place to verify dataframe operations and coordinate cleanup patterns.
Creating Choropleth Maps
Choropleth map is a thematic map that uses color gradients to represent data values across geographic areas. Instead of plotting individual points, you color states, counties, districts, or countries based on a metric such as population, income, or sales.
To build a choropleth, you need a data table and a geographic boundary file, usually GeoJSON. The map joins your values to polygons using a shared key like state name, county code, or country code.
How The Join Works
The basic workflow is simple but strict. Your data key and your boundary feature key must match exactly, or the choropleth will show blank regions.
- Prepare a table with region names or codes.
- Load a GeoJSON file with the matching regions.
- Choose a color scale that reflects low-to-high values clearly.
- Bind the data to the geometry through a common key.
- Render the map and inspect the legend for interpretation.
Choosing bins matters. A poor color scale can hide meaningful differences, while a good scale makes regional patterns obvious in one glance. Sequential palettes usually work best for numeric ranges, while diverging palettes are better when you want to show values above and below a midpoint.
Common use cases include election results, income levels, unemployment rates, sales by region, and population density. For official geospatial and data visualization methods, the GeoJSON specification is the authoritative definition for the format.
Using GeoJSON And Layered Boundaries
GeoJSON is a format for describing geographic features like points, lines, and polygons in a way web maps can render directly. In Folium, GeoJSON overlays let you add custom boundaries such as delivery zones, district outlines, and service regions on top of a base map.
This is one of the most useful techniques when a simple marker map is not enough. A boundary layer can show coverage areas, compare neighboring regions, or highlight where a policy, service, or incident dataset applies.
Styling And Interaction
GeoJSON layers can be styled with fill color, line weight, transparency, and hover behavior. That means you can create a subtle outline for reference or a strongly highlighted polygon that reacts when users move the cursor over it.
Attribute data can also be bound to features. For example, a district polygon can display its name, manager, case count, or inspection status in a popup or tooltip.
Layered boundaries turn a static map into a comparison tool, which is often more valuable than the map itself.
Layering is especially effective when you want to compare multiple geographic datasets in one view. For example, a delivery zone layer can sit on top of customer density points, or administrative regions can be combined with incident clusters to reveal service gaps.
For file integrity and structure, review the IETF RFC 7946 definition of GeoJSON. That specification helps avoid malformed boundary files that do not render correctly.
Adding Heatmaps And Density Visualizations
Heatmap is a density visualization that represents concentration or intensity rather than individual points. It is the better choice when you want to show where something happens most often, not every single occurrence separately.
Heatmaps work well for taxi pickups, crime reports, foot traffic, customer activity, and other concentrated patterns. If the point cloud is too dense for markers, a heatmap usually gives the reader a clearer answer faster.
Preparing Heatmap Data
Folium heatmaps typically use coordinate pairs, and sometimes a weight column to show magnitude. Weighted points are useful when some observations should count more than others, such as high-frequency events or high-priority records.
- Use weights for repeated events or severe incidents.
- Use sampling when the raw dataset is too large.
- Use filtering to keep only the time window or region you care about.
Heatmaps can be misleading if the reader assumes color means exact counts. They are best used as a directional tool, not as a precise reporting chart. Keep labels, scale context, and legends clear so users do not overinterpret the color intensity.
The official Folium plugin behavior is documented by the project itself at Folium, and that should be your first stop when you need plugin syntax or parameter details.
Customizing Interactivity And Visual Design
Folium becomes much more useful when you let users toggle layers, inspect details, and compare datasets. Layer control adds a switchable interface so viewers can turn overlays on and off instead of staring at one crowded view.
Clear design also matters. A map that uses too many bright colors, too many icons, or too many popups becomes hard to scan, especially on mobile screens or inside embedded reports.
Usability Improvements That Matter
- Use layer controls to separate base maps, markers, and thematic overlays.
- Limit clutter by clustering points or filtering unnecessary records.
- Pick readable colors that work on both light and dark backgrounds.
- Style popups consistently so key information appears in the same place every time.
Legends and captions are essential for choropleths and thematic layers. Without them, the map may look polished but still fail at communication. A user should be able to answer “what does this color mean?” without guessing.
Responsiveness matters when a map is embedded in a dashboard or report. Test the output in a browser, inside the target page, and on different screen sizes so the controls do not break or overlap.
For practical map interaction patterns, the Leaflet reference is helpful because Folium inherits much of its behavior from Leaflet under the hood.
Integrating Folium With Pandas And Geospatial Data
Folium works best when it is paired with Pandas for tabular data and GeoPandas for spatial preprocessing. Geospatial data is data tied to coordinates, shapes, or location-based attributes, and this combination lets you move from raw records to a meaningful map quickly.
CSV files are common for point data, while GeoJSON and shapefiles are common for polygons and boundaries. Many real projects need both: tabular records for the values and boundary files for the shapes.
Preparing Data Before Mapping
- Load the source file and inspect the columns.
- Convert coordinate fields to numeric types.
- Drop missing locations or mark them for review.
- Group or aggregate rows if you need counts by region.
- Export cleaned data for mapping and reuse.
GeoPandas is especially helpful when you need to dissolve boundaries, reproject spatial data, or clip features before plotting. That preprocessing step can save time and improve map clarity because you only visualize the geometry that matters.
Data wrangling often reveals patterns that tables hide. For example, customer complaints may look evenly distributed in a spreadsheet but form a clear cluster once plotted on a map, which changes the priority of the investigation.
For official Python ecosystem documentation, check GeoPandas and Pandas.
How To Save, Share, And Embed Folium Maps?
The answer is to save the map as HTML and treat it like a browser-native report. As of May 2026, that is still the simplest and most portable way to distribute a Folium output.
Saving is straightforward with m.save("filename.html"). After that, you can open the file locally, attach it to email, store it in a shared drive, or place it on internal web hosting for team access.
Sharing Options
- Local browser viewing for quick validation and offline review.
- Cloud storage for controlled internal distribution.
- Static hosting for simple web access without a backend.
- Notebook reports for analysis delivered alongside code and narrative.
Embedding is often the most practical choice when a map belongs inside a dashboard or report page. Because Folium exports standard HTML, it can usually be embedded with an iframe or included in a generated report workflow.
Keep file size in mind when the map contains many points or complicated polygons. Simplifying geometry, clustering points, and removing unused layers can make a huge difference in load time and browser stability.
For browser and HTML behavior, the W3C HTML standards are the appropriate reference point, and for map export details the Folium documentation remains the practical source.
Performance Tips And Common Pitfalls
Large map datasets can make rendering slow because the browser has to draw every point, line, popup, and polygon. The fastest fix is usually clustering, filtering, or sampling instead of trying to render everything at once.
Another common problem is coordinate reference system mismatch. Folium expects latitude and longitude in WGS84-style coordinates for normal web mapping, so projected coordinates from GIS software need to be converted before plotting.
Common Mistakes To Catch Early
- Reversed coordinates that place points on the wrong continent.
- Mismatched join keys that leave choropleths blank.
- Invalid GeoJSON files that fail silently or render partially.
- Overloaded layers that obscure the actual insight.
Debugging starts with simple checks. Print the first few rows of your data, verify column names, inspect coordinate ranges, and compare the map center to the expected geographic extent. A bounding box check can quickly reveal whether your points are where you think they are.
Keep layers purposeful. If a layer does not help the reader answer a question, remove it. A clear map beats an impressive but confusing one every time.
The NIST approach to clear, reproducible technical practice is a good reminder here: make your assumptions explicit, validate inputs, and document the output path.
What Are Real-World Use Cases And Project Ideas?
Folium is useful anywhere location data needs to become something a human can inspect quickly. A retail team can build a store locator, a logistics team can map delivery hubs, and a security analyst can display incident patterns or service coverage gaps.
Dynamic projects become even stronger when you connect Folium to APIs or live feeds. For example, you could refresh weather alerts, emergency calls, or asset status every time the map is generated and then export the current state as HTML.
Project Ideas Worth Building
- Retail store locator with categories, hours, and tooltips.
- Travel planner with routes, landmarks, and day-by-day points of interest.
- Service coverage map with customer density and regional boundaries.
- Emergency response dashboard with live incident clustering and zones.
- Environmental event map with heat layers and polygon overlays.
For portfolio value, choose a project that combines cleaning, analysis, and visualization. A strong example is a neighborhood analysis map that layers demographic data, property listings, and transit access, because it shows both technical range and decision-making context.
That same approach works for cybersecurity workflows too. If you are following the CEH v13 course path, location-based mapping can help you visualize asset exposure, suspicious infrastructure, or incident distribution in a way that supports faster analysis.
For workforce and geography-related context, the Bureau of Labor Statistics Occupational Outlook Handbook is useful when you want to compare analytics and IT role growth, while the mapping side should stay grounded in the official Folium and Leaflet documentation.
Key Takeaway
- Folium turns Python data into interactive HTML maps that work well for dashboards, reports, and browser sharing.
- The core workflow is simple: create a map, add markers or layers, then save the result as HTML.
- Choropleths, GeoJSON overlays, clustered points, and heatmaps each solve different mapping problems.
- Clean coordinates, matching keys, and purposeful layers matter more than fancy styling.
- Folium becomes far more useful when paired with Pandas and GeoPandas for real data preparation.
Certified Ethical Hacker (CEH) v13
Learn essential ethical hacking skills to identify vulnerabilities, strengthen security measures, and protect organizations from cyber threats effectively
Get this course on Udemy at the lowest price →Conclusion
Folium gives Python users a practical way to turn location data into interactive, browser-friendly maps. It handles the core jobs well: markers, clustering, choropleths, GeoJSON overlays, and heatmaps.
The best way to use it is to start small. Build a basic map, verify your coordinates, then add layers, styling, and interactivity only when they help the viewer understand the data faster.
If you want a simple rule to follow, make the map answer one clear question. That is how raw location data becomes usable geographic insight, and it is why python folium remains a solid tool for analysts, developers, and security professionals alike.
Folium and Leaflet.js are trademarks of their respective owners.