5

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

7

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)

#...
0
0

Check the condition

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 or elevation< 3000:# Check here i too had same problem
        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")
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.