In [1]:
import os
import folium

print(folium.__version__)


0.8.3+52.g2758dc7.dirty

Load GeoJSON as in GeoJSON_and_choropleth.ipynb.


In [2]:
import json
import requests

url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data'
us_states = f'{url}/us-states.json'
geo_json_data = json.loads(requests.get(us_states).text)

Using CustomPane to place labels above choropleth

Map without custom pane


In [3]:
m = folium.Map([43, -100], zoom_start=4, tiles="stamentoner")

folium.GeoJson(geo_json_data).add_to(m)

m.save(os.path.join('results', 'CustomPanes_0.html'))

m


Out[3]:

Map with custom pane


In [4]:
m = folium.Map([43, -100], zoom_start=4, tiles="stamentonerbackground")

folium.GeoJson(geo_json_data).add_to(m)

folium.map.CustomPane("labels").add_to(m)

# Final layer associated to custom pane via the appropriate kwarg
folium.TileLayer("stamentonerlabels", pane="labels").add_to(m)

m.save(os.path.join('results', 'CustomPanes_1.html'))

m


Out[4]:

Same, but with a different tileset


In [5]:
m = folium.Map([43, -100], zoom_start=4, tiles="CartoDBPositronNoLabels")

folium.GeoJson(geo_json_data).add_to(m)

folium.map.CustomPane("labels").add_to(m)

# Final layer associated to custom pane via the appropriate kwarg
folium.TileLayer("CartoDBPositronOnlyLabels", pane="labels").add_to(m)

m.save(os.path.join('results', 'CustomPanes_2.html'))

m


Out[5]: