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.

ValueError: blue is not a valid ColorBrewer code

See original GitHub issue

Please add a code sample or a nbviewer link, copy-pastable if possible

# Your code here
def my_colors(feature):
    """Postcodes will be colored based on the drive time assigned to """
def my_colors(feature):
    """Postcodes will be colored based on the drive time assigned to """
    if drive_time[feature['drv_tm']] == 30:
        return #1b9e77
    if drive_time[feature['drv_tm']] == 45:
        return #d95f02
    if drive_time[feature['drv_tm']] == 60:
        return #7570b3
    if drive_time[feature['drv_tm']] == 75:
        return #e7298a
    if drive_time[feature['drv_tm']] == 90:
        return #66a61e
    if drive_time[feature['drv_tm']] == 120:
        return #e6ab02
    else: 
        return #a6761d    
    
style_function=lambda feature:{
        'fillColor': my_colors(feature)
        ,'color': 'black'
        ,'weight': 2
        }  
    
style_function=lambda feature:{
        'fillColor': my_colors(feature)
        ,'color': 'black'
        ,'weight': 2
        }

layer= folium.features.Choropleth(
    geo_data= gjson_dt # gjson_dt, is the geojson feature object created from the geodataframe
    ,data=drive_time #dataframe that contain the postgres table related to the geojson file
    ,style_function= style_function
    ,name= 'drv_time' # name of the layer
    ,key_on='feature.properties.postcode' # Feature ID of the dataframe in this case 'postcode'
    ,columns= ['postcode', 'drv_tm']# column to use for the choropleth
    ,highlight=True # highlight the polygon and zoom in to it when you click on the polygon
    ,legend_name='Drive Time' # legend name
m.add_child(layer)

Problem description

I’m trying to display a thematic map with folium using values from a column and a function (color ramp) but I’m getting ValueError: blue is not a valid ColorBrewer code as result.

[this should explain why the current behavior is a problem and what is the expected output.]

Expected Output

I’m expecting to get a map with specific color based on a column [‘drv_tm’] values and function that contain the color ramp

Output of folium.__version__

0.8.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fulloniccommented, Jun 20, 2019

@Gustacro can you place here all the output error? I think that what is creating your error is the Choropleth default value of fill_color=blue.

From Choropleth docstring:

   fill_color: string, default 'blue'
        Area fill color. Can pass a hex code, color name, or if you are
        binding data, one of the following color brewer palettes:
        'BuGn', 'BuPu', 'GnBu', 'OrRd', 'PuBu', 'PuBuGn', 'PuRd', 'RdPu',
        'YlGn', 'YlGnBu', 'YlOrBr', and 'YlOrRd'.

But in fact, currently, only the brewer palettes codes are working. Passing a color hex code gives the same error.

0reactions
Conengmocommented, Nov 26, 2022

Pretty sure the original issue has been solved by https://github.com/python-visualization/folium/pull/1288

Read more comments on GitHub >

github_iconTop Results From Across the Web

"blue is not a valid ColorBrewer code" Error while creating ...
As you can see there is no blue in the base codes, but the default param for fill_color in folium.features.Choropleth is 'blue'.
Read more >
Choropleth maps Classwork, Seminar 4, MHC, CUNY, Spring ...
If we set it to "Blue": we get the error: ... in choropleth raise ValueError('Please pass a valid color brewer code to '...
Read more >
GeoJSON and Choropleth maps lab, Spring 2017
5/site-packages/folium/folium.py", line 601, in choropleth raise ValueError('Please pass a valid color brewer code to ' ValueError: Please pass a valid color ...
Read more >
branca.utilities.color_brewer Example - Program Talk
python code examples for branca.utilities.color_brewer. ... raise ValueError('Please pass a valid color brewer code to ' 'fill_local.
Read more >
Source code for proplot.styletools
*No*. Try using @timer on # register functions, turns out worst is colormap one at 0.1 seconds. ... 3: raise ValueError(f'Invalid RGB argument...
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