gpt4 book ai didi

python - 为什么在 Folium 中使用超过 100 个圆形标记进行绘图会导致 map 空白?

转载 作者:行者123 更新时间:2023-12-01 02:34:42 28 4
gpt4 key购买 nike

我正在使用 Folium 制作一系列用于动画演示的 map ,而我的代码(绘制超过 100 个圆圈时)总是以空白 map 结束。如果我将圆圈数量减少到 100 或以下,效果就很完美。这是 folium 限制还是我可以在本地计算机上使用 Java 或浏览器设置进行更改?我在 Ubuntu 上的 chrome 中的 jupyter 笔记本中使用 python。merged_hourly 是一个 pandas df,包含特定站点、纬度、经度等的纽约市人流量数据。

导出的数据框作为电子表格位于此处: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 列/系列中包含一行带有撇号/单引号的行,该行不会导致错误,但也不会渲染 map 。

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

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

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

关于python - 为什么在 Folium 中使用超过 100 个圆形标记进行绘图会导致 map 空白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46376591/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com