我想创建一个代表参数“有效性”的大叶热图。
我收到带有以下代码的地图:
“”“
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")
“”“
但是我需要具体说明我的观点。 我的数据显示如下:
“”“
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
“”“
我期望值“可用性”为100-绿色,为0-红色。介于两者之间的将是绿色和红色之间的渐变。
我该怎么做?
答案 0 :(得分:1)
我认为您可以利用gradient
中的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