I'm making a heatmap for NYC apartment price using folium. I'm trying to use my own color gradient. When I specify the gradient argument in heatmap function, nothing shows on my map. Does anyone know how to generate our own color gradient and ideally a gradient bar on the map? Thanks a lot.
Here is my code: The first two columns of data are locations. The third column is price.
data =[[ 40.7726, -73.9568, 1900. ],
[ 40.7785, -73.9556, 3200. ],
[ 40.7216, -73.9809, 5800. ],
[ 40.7384, -73.9848, 2900. ],
[ 40.7678, -73.9915, 3312. ],
[ 40.7659, -73.9574, 2600. ],
[ 40.7092, -74.0137, 4299. ],
[ 40.7384, -73.982 , 5750. ],
[ 40.7312, -73.9896, 3595. ]]
from folium.plugins import HeatMap
hmap = folium.Map(location=[40.75, -73.97], tiles='stamentoner',control_scale = True, zoom_start=13)
hmap.add_child(HeatMap(data, radius = 10, gradient={1000: 'blue', 3000: 'lime', 5000: 'red'}))
hmap
The gradient does not take the values of the magnitude as the dict keys for gradient.
Change
hmap.add_child(HeatMap(data, radius = 10, gradient={1000: 'blue', 3000: 'lime', 5000: 'red'}))
to
hmap.add_child(HeatMap(data, radius = 25, gradient={.4: 'blue', .65: 'lime', 1: 'red'}))
And it will work.
From the JS template code of folium, the values of gradient should be between 0 to 1. eg:
gradient={'0':'Navy', '0.25':'Blue','0.5':'Green', '0.75':'Yellow','1': 'Red'}
https://cdn.jsdelivr.net/gh/python-visualization/folium@master/folium/templates/leaflet_heat.min.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With