#288 Map background with folium

Folium is a python library allowing to call the Leaflet.js Javascript library. It allows you to manipulate your data with python and map them using the power of leaflet! It is really easy to call a map using this library. Your first need to install it using

pip install folium

Then, use the folium.Map function to initialise a map. Several tiles are available: OpenStreetMap, Stamen Terrain, Stamen Toner, Mapbox Bright, and Mapbox Control Room. Note that the tile you need probably depends on the zoom you want to apply to your map. Here are a few example, with 2 different degree of zoom.

Low zoom


Mapbox Bright

Mapbox Control Room

 

Stamen Toner

OpenStreetMap

Strong zoom


Mapbox Bright

Stamen Toner

Stamen Terrain

OpenStreetMap

 

Code



# import the library
import folium

# Make an empty map
m = folium.Map(location=[20, 0], zoom_start=3.5)

# Other tiles:
# OpenStreetMap, Stamen Terrain, Stamen Toner, Mapbox Bright, and Mapbox Control Room
m = folium.Map(location=[48.85, 2.35], tiles="Mapbox Bright", zoom_start=2)
m.save('PNG/CARTO/#288_basic_folium_map2.html')
m = folium.Map(location=[48.85, 2.35], tiles="Mapbox Control Room", zoom_start=2)
m.save('PNG/CARTO/#288_basic_folium_map3.html')
m = folium.Map(location=[48.85, 2.35], tiles="Stamen Toner", zoom_start=2)
m.save('PNG/CARTO/#288_basic_folium_map4.html')
m = folium.Map(location=[48.85, 2.35], tiles="OpenStreetMap", zoom_start=2)
m.save('PNG/CARTO/#288_basic_folium_map5.html')

# Same but with a zoom
m = folium.Map(location=[48.85, 2.35], tiles="Mapbox Bright", zoom_start=10)
m.save('PNG/CARTO/#288_basic_folium_map6.html')
m = folium.Map(location=[48.85, 2.35], tiles="Stamen Toner", zoom_start=10)
m.save('PNG/CARTO/#288_basic_folium_map7.html')
m = folium.Map(location=[48.85, 2.35], tiles="Stamen Terrain", zoom_start=10)
m.save('PNG/CARTO/#288_basic_folium_map8.html')
m = folium.Map(location=[48.85, 2.35], tiles="OpenStreetMap", zoom_start=10)
m.save('PNG/CARTO/#288_basic_folium_map9.html')

 

Leave a Reply

Your email address will not be published.