ekim420
ekim420

Reputation: 465

Is there a limit to plotting markers with folium?

I'm plotting the missions ran by the USAF on North Korea during the Korean War.

The following is the map with 2800 plots.

enter image description here

I have a total of about 7500 plots, but whenever I try to plot above 2800 a blank map renders. I'm rendering on a pc laptop. Would it render if I use a desktop? Or is this a limit with folium?

I'm not speculating that it's an issue with the data. I'll share the coordinates data in case someone would like to explore it: link to public excel sheet.

Upvotes: 9

Views: 11523

Answers (2)

DavidDr90
DavidDr90

Reputation: 569

As @Bob Haffner suggested you can use FastMarkerCluster from Folium library. Here is my code, in my file there is ~500K points.

import pandas as pd
import json
from folium.plugins import FastMarkerCluster

rome_lat, rome_lng = 41.9028, 12.4964
with open("file_name.json", 'r') as f:
  # create a new DataFrame
  samples = pd.DataFrame(json.loads(f.read()))        
# init the folium map object
my_map = folium.Map(location=[rome_lat, rome_lng], zoom_start=5)
# add all the point from the file to the map object using FastMarkerCluster
my_map.add_child(FastMarkerCluster(samples[['latitude', 'longitude']].values.tolist()))
# save the map 
my_map.save("save_file.html")

This code takes ~10ms to render the map.

For more details example please follow this link: FastMarkerCluster example

Hope this is helpful.

Upvotes: 12

user13988995
user13988995

Reputation: 11

Another option is that we can add a specific number of markers(let's say 3000 markers) on a layer, using folium.map.FeatureGroup() function that will add 3000 markers on a single layer, and we can add that layer to the map using add_child() function, which reduces the number of layers on the map. I got the result for 20,000 Markers and 3000 line string. And is able to load within 40-45 seconds.

Upvotes: 1

Related Questions