my_map = folium.Map(location=[ave_lat, ave_long], zoom_start=14)
folium.PolyLine(points, color="blue", weight=2.5, opacity=1).add_to(my_map)
my_map
答案 0 :(得分:0)
您可以将rgba值添加到每个点的color关键字。
答案 1 :(得分:0)
我想我也可以添加自己的答案,因为@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
和与speeds
一样多的行points
。
请注意,您可以根据自己的需要更改cm.cividis
(请参见参考文献here)