我正在尝试创建一个热图,以显示上午6点至上午9点的用户模式。从https://gis.stackexchange.com/questions/341004/folium-plugins-heatmapwithtime-no-longer-produces-an-output?newreg=90f7365b57ec4a638c16c1e97739c04a开始,此人遇到了基本问题,即基本地图可以工作,但是没有动态热图。他们通过更新叶片版本解决了该问题。我已经升级到folium 0.10.1,但仍然无法正常工作。
我已经用我的代码尝试过,并且来自示例https://www.kaggle.com/daveianhickey/how-to-folium-for-maps-heatmaps-time-data#Heatmap-with-time-series的代码仍然无法正常工作。
这是我的代码:
map_hooray = folium.Map(
location=[22.500605, 17.036672],
zoom_start=13
)
heat_data = [[[row['lat'], row['lon']] for index, row in df[df['hour'] == i].iterrows()] for i in range(5, 8)]
hm = plugins.HeatMapWithTime(heat_data,
min_opacity=0.1,
gradient={0.3: 'blue', 0.5: 'lime', 0.7: 'orange', 0.9: '#FC3800', 1: 'red'}
)
hm.add_to(map_hooray)
map_hooray
我的df外观如下:
lat lon hour
date
2020-01-01 05:44:33 46.33 23.33 6
2020-01-01 05:12:33 56.33 43.33 7
2020-01-01 07:34:33 66.33 53.33 7
2020-01-01 08:45:33 16.33 53.33 7
2020-01-01 09:38:33 36.33 63.33 8
提前感谢。
感谢https://github.com/python-visualization/folium/issues/1221
渲染功能中的heat_map_withtime.py文件内部替换为https://rawcdn.githack.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.min.js
with
https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.timedimension.min.js
并且一切正常。这是因为传单中的最新更新。