Folium map-based visualization in Python

Using Folium in Python one can display maps. Folium can be installed using pip install.

Folium make use of the leaflet.js library. In a previous post I already demonstrated how to e.g. plot markers and heatmaps onto maps in R, using the Leaflet R package.

In this post I give a brief introduction to Folium in Python.

Below is an example creating a simple map using Folium in Python:

# import folium in Python
import folium
# use the Map function from folium to generate a map

Using the location parameter one can feed a center point to the Map function – in form of a list with latitude and longitude coordinates:

# calling Map() function using the location parameter

The function supports additional parameters, such as e.g. the zoom level:

# making use of start_zoom parameter
          zoom_start = 3)

The “tile” parameter is a parameter enabling the user to select a certain map style. Below I e.g. use the “Stamen Toner” map tiles:

# making use of the tile parameter in Map() function
          zoom_start = 5,
          tiles= "Stamen Toner")

Using folium, i.e. leaflet.js library, one can create markers similar to the ones demonstrated in R.

For this, create a map with folium() – and add markers to it createde with the .Marker() function. An example is displayed below:

# create map object with folium.Map()
mapObject = folium.Map(location = [45,45],
                      zoom_start = 5)
# create markers with .Marker
markerObjects = folium.Marker(location= [45.5,44.5],
                             popup = "This is a marker!")
# add marker to map
# display map with marker

Below I add another marker with a red cloud icon:

# creating additional marker in red
redMarkerObject = folium.Marker(location = [43,43],
# add marker in red to map
# display map with additional markers

Instead of marker icons such as the ones displayed above one could also add e.g. circles, heatmaps etc. I will post additional coding examples in Python, using Folium.

You May Also Like

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.