Skip to content

Instantly share code, notes, and snippets.

@amitrani6
Created June 15, 2022 03:56
Show Gist options
  • Save amitrani6/f8f63046c428c2e9f4562b914cc96eea to your computer and use it in GitHub Desktop.
Save amitrani6/f8f63046c428c2e9f4562b914cc96eea to your computer and use it in GitHub Desktop.
import branca
# Create the map object
m = folium.Map(location=[48, -102], zoom_start=3)
# Create the colomap styles
colormap = branca.colormap.LinearColormap(
vmin=us_data_gdf["Total_Pop_2021"].quantile(0.0),
vmax=us_data_gdf["Total_Pop_2021"].quantile(1),
colors=["red", "orange", "lightblue", "green", "darkgreen"],
caption="Total Population By State",
)
# Create the Choropleth
folium.GeoJson(
us_data_gdf,
style_function=lambda x: {
"fillColor": colormap(x["properties"]["Total_Pop_2021"])
if x["properties"]["Total_Pop_2021"] is not None
else "transparent",
"color": "black",
"fillOpacity": 0.4,
},
).add_to(m)
# Display the Choropleth
m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment