Ken
Ken

Reputation: 111

How Can I Render More Than 1000 Points in Folium

I am trying to render 15,000 points in folium. When I have less than 1000 points I get a map that renders as the attached image (example map). When I include over 1000 my code returns an item void of either a map or points. The following is my code:

example map

z230['marker_color'] = pd.cut(z230['ClosePrice'], bins=5, 
                          labels=['blue','green','yellow','orange','red'])

m = folium.Map(location=[39.2904, -76.6122], zoom_start=12)

for index, row in z230.iterrows():
    folium.CircleMarker([row['Latitude'], row['Longitude']],
                radius=15, color=row['marker_color']).add_to(m)
m

Upvotes: 7

Views: 2609

Answers (1)

RandomForestRanger
RandomForestRanger

Reputation: 277

The only useful workaround I could find was to include cluster markers.

from folium.plugins import FastMarkerCluster

x = #your centering coordinates here LAT
y = #your centering coordinates here LONG
z = #your zoomlevel here

your_map = folium.Map(location=[x, y], tiles="OpenStreetMap", zoom_start=z)

callback = ('function (row) {' 
                'var circle = L.circle(new L.LatLng(row[0], row[1]), {color: "red",  radius: 10000});'
                'return circle};')


your_map.add_child(FastMarkerCluster(your_df[['your_LAT_col', 'your_LONG_col']].values.tolist(), callback=callback))

your_map

Upvotes: 2

Related Questions