Search code examples
pandasjupytergeojsonchoroplethfolium

folium choropleth and geojson not rendering in jupyter


I cannot get a folium map to display in jupyter when all 33 London boroughs are included in the geojson file

but

I can get the folium map to display if fewer boroughs are included in the geojson file. (up to 23)

If I save the map as an html file and open it separately it works just fine.

here is the version of the code that works (just using the first 23 boroughs).

m = folium.Map(location=[51.5, -0.1], zoom_start=10)

m.choropleth(
    geo_data={"type":geo_london["type"],"features":geo_london["features"][:23]}, # 23 of the boroughs
    data=df["Underground"],
    columns=["LA",'Underground'],
    key_on='feature.properties.name',
    fill_color='BuPu',
    fill_opacity=0.9,
    line_opacity=0.2,
    legend_name='Underground Useage',
    highlight=True
)

Here is the version that doesn't work:

m = folium.Map(location=[51.5, -0.1], zoom_start=10)

    m.choropleth(
        geo_data= geo_london, # all 33 boroughs
        data=df["Underground"],
        columns=["LA",'Underground'],
        key_on='feature.properties.name',
        fill_color='BuPu',
        fill_opacity=0.9,
        line_opacity=0.2,
        legend_name='Underground Useage',
        highlight=True
    )

Other things to note:

  • I parsed the geojson file using json within python so geo_london is a dictionary
  • if I do m.save('mymap.html') and open the map the second version also works fine.
  • I have the same problem if I don't use the data in a chorepleth but instead use folium.GeoJson(geo_london).add_to(m)
  • folium 0.5.0
  • the data is a pandas data series

Solution

  • Probably you are describing the bug explained here https://github.com/python-visualization/folium/issues/768 (Folium displays nothing if number of overlaid images > 80 on Chrome). Try to use a different browser like Firefox or Safari.