folium: Choropleth Colors not Displaying

Like issue #92, the colors on the Choropleth are not displaying. What is odd is the quantiles are being set and the data.json file contains the valid values, but all of the shapes of the same color.

I’m doing something wrong, but can’t figure out what it is. The data files are in the same directory, so the solution isn’t the same as #92.

import folium
import pandas as pd

state_geo = r'gz_2010_us_040_00_20m.json'
population = r'd.csv'

state_data = pd.read_csv(population)

#Let Folium determine the scale
map = folium.Map(location=[48, -102], zoom_start=3)
map.geo_json(geo_path=state_geo, data=state_data, data_out='data.json',
                columns=['state', 'D001'],
                key_on='feature.NAME',
                fill_color='YlGn', fill_opacity=0.7, line_opacity=0.1,
                legend_name='population')
map.create_map(path='index.html')

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 23 (12 by maintainers)

Most upvoted comments

The problem is in your JSON:

{ "type": "Feature", 
  "properties": { "GEO_ID": "0400000US04",
                        "STATE": "04",
                        "NAME": "Arizona",
                        "LSAD": "",
                        "CENSUSAREA": 113594.084000 }, "geometry":{...}...

You are using a key_on=feature.NAME and the NAME does not exist in Feature. NAME is inside properties. The docs do say that feature.properties.NAME should work, but I just tested that and it is broken. Your best option is to use this GeoJSON and adapt your DataFrame to be the two letter code for the states.

(Next time please use links to all files. It is time consuming to copy-and-paste to create a csv just to test it.)