Code
```{python}
import folium
from folium.plugins import Draw
# Create a map centered on a location
m = folium.Map(
location=[communities["centroid_lat"].mean(), communities["centroid_lon"].mean()],
zoom_start=9,
)
# 3. Define a simple function to assign a color based on the 'category' column
def get_color(district):
if district.lower() == "karaga":
return "blue"
elif district.lower() == "mion":
return "green"
else:
return "red"
# 4. Loop through each row in the DataFrame to add a CircleMarker
for idx, row in communities.iterrows():
# Calculate radius with exponential growth
# np.exp() provides the exponential scaling.
# The scaling factor (0.5) is crucial for adjusting the final visual size.
# You may need to change this factor based on your data's range.
radius = row["num_hh"] * 25
# Add the CircleMarker to the map
folium.Circle(
location=[row["centroid_lat"], row["centroid_lon"]],
radius=radius,
color=get_color(row["district"]),
fill=True,
fill_color=get_color(row["district"]),
fill_opacity=0.6,
popup=f"Community: {row['community']}<br>Households: {row['num_hh']}",
tooltip=f"Community: {row['community']}<br>Households: {row['num_hh']}",
).add_to(m)
# Add the drawing toolbar
draw = Draw(
export=True, # Allows you to export the drawing as a GeoJSON file
filename="my_route.geojson",
draw_options={
"polyline": {"shapeOptions": {"color": "orange"}},
"polygon": False,
"circle": False,
"rectangle": False,
"marker": False,
"circlemarker": False,
},
)
draw.add_to(m)
m
```Make this Notebook Trusted to load map: File -> Trust Notebook