Is there a way to plot many markers in Folium?

筅森魡賤 提交于 2019-12-08 06:46:17

问题


I am trying to use Folium for geographical information reading from a pandas dataframe. The code I have is this one:

import folium
from folium import plugins
import pandas as pd

...operations on dataframe df...

map_1 = folium.Map(location=[51.5073219, -0.1276474],
                   zoom_start=12,
                   tiles='Stamen Terrain')
markerCluster = folium.plugins.MarkerCluster().add_to(map_1)
lat=0.
lon=0.
for index,row in df.iterrows():
    lat=row['lat]
    lon=row['lon']
    folium.Marker([lat, lon], popup=row['name']).add_to(markerCluster)
map_1

df is a dataframe with longitude, latitude and name information. Longitude and latitude are float. I am using jupyter notebook and the map does not appear. Just a white empty box. I have also tried to save the map:

map_1.save(outfile='map_1.html')

but also opening the file doesn't work (using Chrome, Firefox or Explorer). I have tried to reduce the number of markers displayed and below 300 markers the code works and the map is correctly displayed. If there are more than 300 Markers the map returns to be be blank. The size of the file is below 5 MB and should be processed correctly by Chrome.

Is there a way around it (I have more than 2000 entries in the dataframe and I would like to plot them all)? Or to set the maximum number of markers shown in folium?

Thanks


回答1:


This might be too late but I stumbled upon the same problem and found a solution that worked for me without having to remove the popups so I figured if anybody has the same issue they can try it out. Try replacing popup=row['name'] with popup=folium.PopUp(row['name'], parse_html=True) and see whether it works. You can read more about it here https://github.com/python-visualization/folium/issues/726



来源:https://stackoverflow.com/questions/49047519/is-there-a-way-to-plot-many-markers-in-folium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!