Search code examples
pythondictionaryplotalphafolium

folium.Choropleth: control fill_opacity for null values only


I have drawn a nice map of the US. I have made Choropleth using Folium

folium.Choropleth(
 geo_data=boundaries,
 name='choropleth',
 data=df,
 columns=['state','NR'],
 key_on='feature.id',
 fill_color='Blues',
 threshold_scale=a_non_unform_log_scale,
fill_opacity=0.7
).add_to(m)

enter image description here

It is exaclty as I wanted, but I would like to give the value 0 a special transparent color. E.g. in the image many states are black because they had a null/nan entry in df. Can I make just transparent the missing states?


Solution

  • Yes, you can. You can do the following:

    folium.Choropleth(
     geo_data=boundaries,
     name='choropleth',
     data=df,
     columns=['state','NR'],
     nan_fill_color='grey',
     nan_fill_opacity=0.4,
     key_on='feature.id',
     fill_color='Blues',
     threshold_scale=a_non_unform_log_scale,
    fill_opacity=0.7
    ).add_to(m)