为什么在Folium中具有超过100个圆形标记的映射会导致空白地图? [英] Why does mapping in Folium with over 100 Circle Markers result in a blank map?

查看:353
本文介绍了为什么在Folium中具有超过100个圆形标记的映射会导致空白地图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Folium为动画演示制作一系列地图,而我的代码(绘制100多个圆时)始终以空白地图结尾.如果我将圆圈数减少到100个或以下,则效果很好.这是folium的限制,还是可以通过Java或浏览器设置在本地计算机上更改的内容?我在Ubuntu上的chrome的jupyter笔记本中使用python. merged_hourly是具有特定站(经纬度,经度等)的nyc脚踏车数据的熊猫df.

I'm working on producing a series of maps for an animated presentation using Folium and my code (when plotting over 100 circles) always ends in a blank map. If I decrease the number of circles to 100 or below, it works perfectly. Is this a folium limitation or something I can change on my local machine with Java or Browser settings? I'm using python in jupyter notebook in chrome on Ubuntu. merged_hourly is a pandas df with nyc foottraffic data for specific stations, lat, long, etc.

导出的数据框以电子表格的形式位于此处: https: //docs.google.com/spreadsheets/d/1XroOBPUWOqZsy-l1dwcR1iuOIn9ln69ylO16_Sqa9yc/edit?usp=sharing

Exported Dataframe is located here as a spreadsheet: https://docs.google.com/spreadsheets/d/1XroOBPUWOqZsy-l1dwcR1iuOIn9ln69ylO16_Sqa9yc/edit?usp=sharing

# iterates columns in df
for myint in range(0,241):
    # iterates rows in df. should go to ~289, but will make a blank map
    for i in range(0,101):
        # sets some variables from the df
        R=merged_hourly[str(myint/10)][i]*.15
        lat=merged_hourly['Station_Latitude'][i]
        long=merged_hourly['Station_Longitude'][i]
        stname=merged_hourly['Station_Name'][i]
        # plots the CircleMarker
        folium.CircleMarker([lat, long], radius=R, popup=stname, color='#3186cc', 
                            fill_color='#3186cc',fill=True,
                            fill_opacity= .7).add_to(map_final)
    # saves a map with all the circle markers in a row
    map_final.save("FilePath/"+str(myint)+'.html')
    map_final=5
    map_final=folium.Map(location=[40.775036, -73.912034], zoom_start=11.25)

推荐答案

OP的数据集在Station_Name列/系列中包含带撇号/单引号的行,该行也不会引起错误,但也没有呈现地图

The OP's dataset contains a row with an apostrophe/single quote in the Station_Name column/Series that wasn't causing an error but wasn't rendering the map either.

filter = merged_hourly['Station_Name'].str.contains("'")
print(merged_hourly.loc[filter,'Station_Name'])

101    E 143/ST MARY'S
Name: Station_Name, dtype: object

解决方案是将单引号替换为',以便呈现地图并在弹出窗口中正确显示Station_Name

Solution was to replace the apostrophe with ' so the map renders and Station_Name correctly shows up in the popup

merged_hourly['Station_Name'] = merged_hourly['Station_Name']
                                              .str.replace("'", "'")

这篇关于为什么在Folium中具有超过100个圆形标记的映射会导致空白地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆