[GIS] Fill color not showing appropriately in folium

foliumpythonpython 3

The following code should have shown different colored circles in a map. But my result was circles with no color at all.

import folium
import pandas

data=pandas.read_csv("Volcanoes.txt")
lat = list(data["LAT"])
lon = list(data["LON"])
elev = list(data["ELEV"])

def color_producer(elevation):
    if elevation < 1000:
        return 'green'
    elif 1000 <= elevation < 3000:
        return 'orange'
    else:
        return 'red'
map = folium.Map(location=[38.58, -99.09], zoom_start=6, tiles="Mapbox Bright")
fg = folium.FeatureGroup(name="My Map")
for lt, ln, el in zip(lat, lon, elev):
    fg.add_child(folium.CircleMarker(location=[lt, ln], radius = 6, popup=str(el)+" m",
    fill_color=color_producer(el), color = 'grey', fill_opacity=0.7))
map.add_child(fg)
map.save("Map1.html")

Can you show me where did I did wrong?

Screenshot of the output

Best Answer

According the documentation, when you're creating a CircleMarker object the fill parameter defaults to False. Try explicitly setting it to True in your code:

#...

for lt, ln, el in zip(lat, lon, elev):
    cm = folium.CircleMarker(location=[lt, ln],
                            radius = 6,
                            popup=str(el)+" m",
                            fill=True, # Set fill to True
                            fill_color=color_producer(el),
                            color = 'grey',
                            fill_opacity=0.7)
    fg.add_child(cm)

#...