Search code examples
pythonheatmapfolium

python folium HeatMapWithTime plugin only showing base map


I am trying to create a heatmap that shows user patterns from 6am~9am. From https://gis.stackexchange.com/questions/341004/folium-plugins-heatmapwithtime-no-longer-produces-an-output?newreg=90f7365b57ec4a638c16c1e97739c04a this person went through exact same problem where base map works however there is no dynamic heatmap. They solved it by updating folium version. I've upgraded to folium 0.10.1 and still not working.

I've tried it with my code, and code from example https://www.kaggle.com/daveianhickey/how-to-folium-for-maps-heatmaps-time-data#Heatmap-with-time-series and still does not work.

Here is my code:

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

where my df looks like:

                               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

Thanks in advance.


Solution

  • Thanks to https://github.com/python-visualization/folium/issues/1221

    Inside heat_map_withtime.py file in render function replaced https://rawcdn.githack.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.min.js

    with

    https://cdn.jsdelivr.net/npm/leaflet-timedimension@1.1.0/dist/leaflet.timedimension.min.js

    and everything works fine. It was because of recent update in leaflet.