我想我最好加上我自己的答案,因为来自@GlobalTraveler的答案涉及到画很多线,我觉得有点脏。在
似乎在叶中确实没有这样做的选择,但你可以画多个标记,并分别给它们着色import numpy as np
from matplotlib import cm
import folium
# rgb tuple to hexadecimal conversion
def rgb2hex(rgb):
rgb = [hex(int(256*x)) for x in rgb)]
r, g, b = [str(x)[2:] for x in rgb]
return "#{}{}{}".format(r, g, b)
# Defines the color mapping from speeds to rgba
color_mapper = cm.ScalarMappable(cmap=cm.cividis)
rgb_values = color_mapper.to_rgba(speeds)[:3] # keep rgb and drop the "a" column
colors = [rgb2hex(rgb) for rgb in rgb_values]
my_map = folium.Map(location=[ave_lat, ave_long], zoom_start=14)
for point, color, speed in zip(points, colors, speeds):
folium.CircleMarker(location=point,
radius=1.25,
popup=str(speed),
fill_color=color).add_to(my_map)
my_map
要实现这一点,您需要有一个包含2列的数组points,以及一个与points一样多行的数组speeds。
请注意,您可以将cm.cividis更改为适合您需要的任何内容(请参阅参考文献here)