python-visualization / folium

Python Data. Leaflet.js Maps.
https://python-visualization.github.io/folium/
MIT License
6.94k stars 2.23k forks source link

Adding Multiple Clusters to map #1961

Closed Andreia183 closed 5 months ago

Andreia183 commented 5 months ago

I'm creating cluster and trying to add them into the map. It works fine with one cluster but any time I try to add a new one the map does not work Below an example with just 2 clusters

# Clusters Creation
cluster1 = df_january[['start_lat','start_lng']][df_january['y_kmean']==0].values.tolist()
cluster2 = df_january[['start_lat','start_lng']][df_january['y_kmean']==1].values.tolist()

#Get map
map = folium.Map(location = [38.983627, -77.006311], zoom_start = 10 , tiles = "OpenStreetMap")
map

# Add clusters in map
for i in cluster1:
    folium.CircleMarker(location = i, radius=2, color='green', fill_color = 'lightgreen').add_to(map)

for i in cluster2:
    folium.CircleMarker(location = i, radius=2, color='red', fill_color = 'lightred').add_to(map)

If I just run for the 1st cluster it works but not when adding a second Screenshot 2024-06-02 193233

I'm working on a Jupyter Notebook.

Is there a way to add multiple clusters in the map? Thank you

hansthen commented 5 months ago

@Andreia183 can you add the input data for this particular example?

Andreia183 commented 5 months ago

@hansthen as an example they are like this: [[38.88532071975074, -77.15642720460892], [38.94660792121498, -77.3393914103508], [38.862437166666666, -77.08655866666666], [38.916442, -77.0682], [38.895377, -77.09713], [38.88837, -77.179832], [38.895068, -77.07386], [38.934881, -77.072755], [38.979875, -77.093522], [38.8881, -77.09308], [38.847129045742605, -77.1125502884388], [38.862478, -77.086599]]

Conengmo commented 5 months ago

Looking at your code this seems unlikely an issue with Folium. Please check your data and make sure cluster1 and cluster2 are actually different.

If you require more help, please include a minimal working example (including data).