Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export python folium heat map with time to html

I have a HeatMapWithTime created with the folium library. The heatmap changes over time. I want to export this map into an HTML in a dynamic format. I want to use this map for presentations without having to run the code. Please I would appreciate it if someone can show me how to export my map without losing the time step.

My map code:

map_Oslo = folium.Map(location=[Latitude, Longitude], zoom_start=5)
plugins.HeatMapWithTime(heat_data, 
                        radius=10,
                gradient={0.1: 'blue', 0.2: 'blue', 0.4: 'lime', 0.6: 'orange', 0.8: 'red', 0.99: 'purple'},
                min_opacity=0.5, max_opacity=0.8, use_local_extrema=False).add_to(map_Oslo)
map_Oslo

enter image description here

I tried some suggestions but I get the error WebDriverException: Message: 'geckodriver' executable needs to be in PATH.and I can not tell if the code works. :

import os
import time
from selenium import webdriver

delay=5
fn='testmap.html'
tmpurl='file://{path}/{mapfile}'.format(path=os.getcwd(),mapfile=fn)
map_Oslo.save(fn)

browser = webdriver.Firefox()
browser.get(tmpurl)
#Give the map tiles some time to load
time.sleep(delay)
browser.save_screenshot('map.png')
browser.quit()
like image 487
Elda Avatar asked May 09 '26 00:05

Elda


1 Answers

Try this simple solution:

map_Oslo.save("heat_map.html")
like image 76
thenarfer Avatar answered May 11 '26 15:05

thenarfer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!