[英]Add arrows on scatter plot between points Pandas
我有一个 dataframe:
import pandas as pd
d = {'year': [2021, 2021, 2021, 2021, 2021], 'month': [3, 4, 5, 8, 9], 'day': [23, 14, 6, 11, 3],
'latitude':[38.23750, 34.07029, 49.71443, 37.77493, 40.71427],
'longitude':[-117.39588, -104.35108, 7.30776,-122.41942, -74.00597],
'brightness':[300, 20, 100, 150, 80]}
df = pd.DataFrame(data=d)
df['datatime'] = pd.to_datetime(df[['year', 'month', 'day']])
我在散点图 plot 上绘制数据,y 轴上的纬度,x 轴上的经度:
df.plot(x="longitude", y="latitude", kind="scatter", c="brightness", s="brightness", alpha=0.5,
colormap="cool")
假设您的日期已排序(如果没有,请按日期排序):
ax = df.plot(x="longitude", y="latitude", kind="scatter",
c="brightness", s="brightness", alpha=0.5,
colormap="cool")
prev = None
for row in df[::-1].itertuples():
if prev:
ax.annotate('',
xy=(prev.longitude, prev.latitude),
xytext=(row.longitude, row.latitude),
arrowprops=dict(arrowstyle="->"),
color='k',
)
prev= row
output:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.