Search code examples
pythonpandasplotdata-sciencefolium

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.


Solution

  • 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.