python色标_在Python中用色标可视化移动速度
我想我最好加上我自己的答案,因為來自@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)
總結
以上是生活随笔為你收集整理的python色标_在Python中用色标可视化移动速度的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql tdh_socket_thr
- 下一篇: php cli swoole mysql