Search code examples
pythondata-sciencegeojsonfoliumchoropleth

color of choropleth map is not changing


issue: Entire choropleth map is displaying in a single color

Here is my GEOjson file

{'type': 'FeatureCollection',
 'features': [{'type': 'Feature',
   'geometry': {'type': 'Polygon',
    'coordinates': [[[139.772865837, 35.703702135],
      [139.77279358, 35.703120198],
      ....
      [139.772865837, 35.703702135]]]},
   'id': '13101'},

.......

I am using 'id' as my key_on paramater.

Here is my dataFrame

           Area    Municipality     Positive  Cases   id
0   Special ward area   Adachi   4769   13121
1   Special ward area   Arakawa  1591   13118
2   Special ward area   Itabashi 3683   13119
3   Special ward area   Edogawa  3853   13123
4   Special ward area   Ota      5255   13111

My map is....

tokyo_map.choropleth(
    geo_data = tokyo_geojson,
    data=df_tokyo,
    columns=['Municipality', 'Positive Cases', 'id'],
    key_on = 'features.id',
    fill_color='Reds',
    threshold_scale=threshold_scale,
    fill_opacity=0.8, 
    line_opacity=0.2,
    legend_name='Corona Cases in Tokyo',
    highlight = True,
    reset=True
)

tokyo_map

The map is shown below.

enter image description here


Solution

  • The 'id' is a property or key of a feature, not features. Change key_on = 'features.id' to key_on = 'feature.id'