Reputation: 185
I want to create a folium heat map that represent parameter "availibity".
I receive the map with this code:
"""
import folium
import pandas as pd
from folium.plugins import HeatMap
# Pulls CSV file from this location and adds headers to the columns
df = pd.read_csv("H:\\result.csv", delimiter=';')
lat = df.lat # Converting Lat/Lon into decimal degrees
lon = df.lon
zoom_start = 25 # Zoom level and starting location when map is opened
mapa = folium.Map(location=[lat[1], lon[1]], zoom_start=zoom_start)
i = 0
location = []
while i < (len(lat)-1):
location.append((lat[i], lon[i]))
i += 1
j = (lat[i] - lat[i - 1])
c1 = folium.PolyLine(locations=[location], color='blue', weight=1.5, opacity=0.5)
c1.add_to(mapa)
location = []
HeatMap(data=df[['lat', 'lon', 'availability']].groupby(['lat', 'lon']).sum().reset_index().values.tolist(), radius=8, max_zoom=13).add_to(mapa)
mapa.save(outfile="H:\\result.html")
"""
But I need specifically color my points. My data looks next way:
"""
14.34600568 48.28124133 100
14.34597853 48.28132943 100
14.34595139 48.28141753 100
14.34592425 48.28150563 100
14.3457984 48.28203327 100
14.34577834 48.2821222 95
14.34575828 48.28221114 98
14.34573822 48.28230007 96
14.34571816 48.28238901 85
14.3456981 48.28247794 75
14.34567804 48.28256688 60
14.34549389 48.28322028 50
14.34547084 48.28330889 40
14.34544779 48.28339751 20
14.34542474 48.28348613 0
14.34540168 48.28357474 0
14.34537863 48.28366336 70
14.34535558 48.28375197 80
14.34514806 48.28450942 85
14.34512447 48.28459798 100
14.34510088 48.28468653 100
"""
What I expected that i have for value "availability" 100 - green color, and for 0 - red color. And what is between will be gradient between green and red.
How can I make this?
Upvotes: 2
Views: 5455
Reputation: 8493
I think you could leverage the gradient
parameters in HeatMap
zoom_start = 25 # Zoom level and starting location when map is opened
mapa = folium.Map(location=[df.lat.mean(), df.lon.mean()], zoom_start=zoom_start)
gradient = {.33: 'red', .66: 'brown', 1: 'green'}
HeatMap(data=df, gradient=gradient, radius=8, max_zoom=13).add_to(mapa)
mapa
Upvotes: 4