有没有办法在Folium中绘制许多标记

有没有办法在Folium中绘制许多标记

本文介绍了有没有办法在Folium中绘制许多标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Folium从熊猫数据框中读取地理信息.我拥有的代码是这样的:

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是一个包含经度,纬度和名称信息的数据框.经度和纬度是浮动的.我正在使用jupyter笔记本,但地图未出现.只是一个白色的空盒子.我也曾尝试保存地图:

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')

,但也无法打开文件(使用Chrome,Firefox或Explorer).我已尝试减少显示的标记数,并且在300个标记以下,该代码可以正常工作,并且地图可以正确显示.如果标记数超过300,则地图将变为空白.文件大小小于5 MB,并且应由Chrome正确处理.

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.

有没有解决的办法(我在数据框中有2000多个条目,我想将它们全部绘制出来)?还是要设置大叶中显示的最大标记数?

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?

谢谢

推荐答案

这可能为时已晚,但我偶然发现了相同的问题,找到了一个对我有用的解决方案,而不必删除弹出窗口,所以我想知道是否有人可以同样的问题,他们可以尝试一下.尝试将popup=row['name']替换为popup=folium.PopUp(row['name'], parse_html=True),然后查看其是否有效.您可以在此处 https://github.com/python-visualization/folium了解更多/issues/726

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

这篇关于有没有办法在Folium中绘制许多标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 05:27