Search code examples
pythonpython-3.xlistrangefolium

Python Folium Module Markers(color issues)


I am currently using folium to plot a list of lat/longs, around 1000 or so points. I have a list called lats, a list called longs and then a third list which is the colors, it is either the colors red, or green. The problem I am having is when I open up the map all the points get turned to red. I have no clue why. It makes zero sense to me because when I make it so it only shows the greens it works fine. But once it starts to show both all the greens turn to red by the end. Does anyone know why?

import folium
from folium import plugins

mapit = folium.Map( location=[map_lat, map_long], zoom_start=10 )
for en in range(0, len(enum)):
    folium.CircleMarker([lats[en], longs[en]], fill = True, color = colors[en], radius = 3, fill_color = colors[en]).add_to( mapit )
mapit.save('map.html')

map_lat, map_long are just some variables for where the map should be pointing.

The len(enum) is a list with equal length to the lats, longs and colors lists. It contains other information not as important to the question, but you can be assured that it is the same length.


Solution

  • Following your description, this toy example gives the expected result:

    import folium
    from folium import plugins
    
    lats = [51.5873, 51.4743, 51.632, 51.4731]
    longs = [0.0873, -0.0703, -0.3032, -0.2731]
    colors = ['red', 'red', 'green', 'green']
    
    mapit = folium.Map(location=[lats[0], longs[0]],
                       zoom_start=10)
    
    for en in range(len(colors)):
        folium.CircleMarker([lats[en], longs[en]],
                            fill = True,
                            color = colors[en],
                            radius = 20,
                            fill_color = colors[en]).add_to( mapit )
    mapit.save('map.html')
    mapit
    

    and you get:

    enter image description here