question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Choropleth Colors not Displaying

See original GitHub issue

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')

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:23 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
ocefpafcommented, Oct 30, 2015

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.)

0reactions
joelsewherecommented, May 15, 2019

I’m trying to color zipcodes in King County according to mean housing prices.

geo_1 is a geojson for each zipcode in King County. It can be found here: https://gis-kingcounty.opendata.arcgis.com/datasets/zipcodes-for-king-county-and-surrounding-area-zipcode-area

final_df is a dataframe with two columns,

folium.Chloropleth() isn’t returning an error, but when I attempt to output m2, I receive this error message:

AttributeError: ‘NoneType’ object has no attribute ‘get’

folium.Choropleth(
    geo_data=geo_1,
    name='choropleth',
    data=final_df,
    columns=['zipcode', 'price'],
    key_on='features.properties.zip',
    fill_color='YlGn',
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name='Housing Priced by `Zipcode` (%)'
).add_to(m2)

folium.LayerControl().add_to(m2)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Choropleth map is not showing color variation in the output
Choropleth map is not showing color variation in the output ; from pandas import ; import os import ; False) vis = os.path.join('Community_Areas....
Read more >
Choropleth map not displaying colors · Issue #917 - GitHub
The geojson map is apparently rendering properly, but the colors from the values in the data.csv aren't showing up at all.
Read more >
Filled map (choropleth) data colors not working
Solved: I'm working on trying to create shading (color scale) on a Filled Map. Following the instructions on.
Read more >
Choropleth map not displaying color-Pandas,Python
[Solved]-Data visualization: Choropleth map not displaying color-Pandas,Python ... We need to link the country abbreviation name to GeoJson's ISO_A3. from urllib.
Read more >
Colors not displaying on Plotly Choropleth Map in iPython ...
Hello I recently downloaded and installed plotly in order to create a Choropleth U.S. map of Zika cases in the iPython notebook.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found