初めて利用させていただきます。
拙い部分もあるかと思いますがお付き合いいただければ幸いです。
現在、プロットを任意の座標通りに動かすアニメーションを作成しており、点を動かすことには成功しているのですが、そのアニメーションのプロットを線で繋ぎたいと考えております。
以下、現在完成しているコードです。
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import animatplot as amp
import matplotlib.animation as animation
import math
#グラフの描画
def plot_animation(ref_df):
#X軸・Y軸のデータ取得
X_data = 0
Y_data = 0
#refの経路描画
time_data_np = np.array(ref_df["time"])
x_np = np.array(ref_df["x"])
y_np = np.array(ref_df["y"])
x2_np = np.array(ref_df["x2"])
y2_np = np.array(ref_df["y2"])
x3_np = np.array(ref_df["x3"])
y3_np = np.array(ref_df["y3"])
x4_np = np.array(ref_df["x4"])
y4_np = np.array(ref_df["y4"])
x5_np = np.array(ref_df["x5"])
y5_np = np.array(ref_df["y5"])
x6_np = np.array(ref_df["x6"])
y6_np = np.array(ref_df["y6"])
x7_np = np.array(ref_df["x7"])
y7_np = np.array(ref_df["y7"])
x8_np = np.array(ref_df["x8"])
y8_np = np.array(ref_df["y8"])
x9_np = np.array(ref_df["x9"])
y9_np = np.array(ref_df["y9"])
x10_np = np.array(ref_df["x10"])
y10_np = np.array(ref_df["y10"])
x11_np = np.array(ref_df["x11"])
y11_np = np.array(ref_df["y11"])
x12_np = np.array(ref_df["x12"])
y12_np = np.array(ref_df["y12"])
x13_np = np.array(ref_df["x13"])
y13_np = np.array(ref_df["y13"])
x14_np = np.array(ref_df["x14"])
y14_np = np.array(ref_df["y14"])
x15_np = np.array(ref_df["x15"])
y15_np = np.array(ref_df["y15"])
x16_np = np.array(ref_df["x16"])
y16_np = np.array(ref_df["y16"])
x17_np = np.array(ref_df["x17"])
y17_np = np.array(ref_df["y17"])
x18_np = np.array(ref_df["x18"])
y18_np = np.array(ref_df["y18"])
x19_np = np.array(ref_df["x19"])
y19_np = np.array(ref_df["y19"])
x20_np = np.array(ref_df["x20"])
y20_np = np.array(ref_df["y20"])
x21_np = np.array(ref_df["x21"])
y21_np = np.array(ref_df["y21"])
x22_np = np.array(ref_df["x22"])
y22_np = np.array(ref_df["y22"])
x23_np = np.array(ref_df["x23"])
y23_np = np.array(ref_df["y23"])
Xs_log =np.asarray([x_np[t:t+1] for t in range(len(time_data_np)-1)]) #X軸データ × 時間軸 分の配列
Ys_log =[y_np[t:t+1] for t in range(len(time_data_np)-1)] #Y軸データ × 時間軸 分の配列
Xs2_log =np.asarray([x2_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys2_log =[y2_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs3_log =np.asarray([x3_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys3_log =[y3_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs4_log =np.asarray([x4_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys4_log =[y4_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs5_log =np.asarray([x5_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys5_log =[y5_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs6_log =np.asarray([x6_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys6_log =[y6_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs7_log =np.asarray([x7_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys7_log =[y7_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs8_log =np.asarray([x8_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys8_log =[y8_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs9_log =np.asarray([x9_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys9_log =[y9_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs10_log =np.asarray([x10_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys10_log =[y10_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs11_log =np.asarray([x11_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys11_log =[y11_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs12_log =np.asarray([x12_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys12_log =[y12_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs13_log =np.asarray([x13_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys13_log =[y13_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs14_log =np.asarray([x14_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys14_log =[y14_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs15_log =np.asarray([x15_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys15_log =[y15_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs16_log =np.asarray([x16_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys16_log =[y16_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs17_log =np.asarray([x17_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys17_log =[y17_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs18_log =np.asarray([x18_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys18_log =[y18_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs19_log =np.asarray([x19_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys19_log =[y19_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs20_log =np.asarray([x20_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys20_log =[y20_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs21_log =np.asarray([x21_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys21_log =[y21_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs22_log =np.asarray([x22_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys22_log =[y22_np[t:t+1] for t in range(len(time_data_np)-1)]
Xs23_log =np.asarray([x23_np[t:t+1] for t in range(len(time_data_np)-1)])
Ys23_log =[y23_np[t:t+1] for t in range(len(time_data_np)-1)]
Time_log =np.asarray([time_data_np[t:t+1] for t in range(len(time_data_np)-1)])
ax1 = plt.subplot2grid((1,1), (0,0), rowspan=3)
ax1.set_xlim([-0.5, 1.3])
ax1.set_ylim([-0.1, 0.8])
block = amp.blocks.Scatter(Xs_log, Ys_log,ax=ax1)
block2 = amp.blocks.Scatter(Xs2_log, Ys2_log,ax=ax1)
block3 = amp.blocks.Scatter(Xs3_log, Ys3_log,ax=ax1)
block4 = amp.blocks.Scatter(Xs4_log, Ys4_log,ax=ax1)
block5 = amp.blocks.Scatter(Xs5_log, Ys5_log,ax=ax1)
block6 = amp.blocks.Scatter(Xs6_log, Ys6_log,ax=ax1)
block7 = amp.blocks.Scatter(Xs7_log, Ys7_log,ax=ax1)
block8 = amp.blocks.Scatter(Xs8_log, Ys8_log,ax=ax1)
block9 = amp.blocks.Scatter(Xs9_log, Ys9_log,ax=ax1)
block10 = amp.blocks.Scatter(Xs10_log, Ys10_log,ax=ax1)
block11 = amp.blocks.Scatter(Xs11_log, Ys11_log,ax=ax1)
block12 = amp.blocks.Scatter(Xs12_log, Ys12_log,ax=ax1)
block13 = amp.blocks.Scatter(Xs13_log, Ys13_log,ax=ax1)
block14 = amp.blocks.Scatter(Xs14_log, Ys14_log,ax=ax1)
block15 = amp.blocks.Scatter(Xs15_log, Ys15_log,ax=ax1)
block16 = amp.blocks.Scatter(Xs16_log, Ys16_log,ax=ax1)
block17 = amp.blocks.Scatter(Xs17_log, Ys17_log,ax=ax1)
block18 = amp.blocks.Scatter(Xs18_log, Ys18_log,ax=ax1)
block19 = amp.blocks.Scatter(Xs19_log, Ys19_log,ax=ax1)
block20 = amp.blocks.Scatter(Xs20_log, Ys20_log,ax=ax1)
block21 = amp.blocks.Scatter(Xs21_log, Ys21_log,ax=ax1)
block22 = amp.blocks.Scatter(Xs22_log, Ys22_log,ax=ax1)
block23 = amp.blocks.Scatter(Xs23_log, Ys23_log,ax=ax1)
#ax1.legend()
#ax2.legend()
plt.subplots_adjust(wspace=0.4, hspace=0.6)
plt.tick_params(labelbottom=False,
labelleft=False)
anim = amp.Animation([block,block2,block3,block4,block5,block6,block7,block8,block9,block10,block11,block12,block13,block14,block15,block16,block17,block18,block19,block20,block21,block22,block23])
anim.controls()
anim.save_gif("result")
plt.show()
if __name__ == '__main__':
csv_file_path = "test3.csv"
ref_df = pd.read_csv(csv_file_path, encoding= "utf-8-sig")
plot_animation(ref_df)
print("finished!")
test3.csvの内容は以下のように座標データが入っているものになっております。
上記のコードを実行すると以下のようなものが出てきます。
便宜上画像を貼っておりますが実際はアニメーションのように動くようになっております。
これを以下のデータのように線で繋いだまま動くようにしたいと考えております。
具体的には以下の5本の線を引きたいと考えております。
block1-4,block5-8,block9-14,block15-20,block21,22,23,20
初心者のため、拙い質問で申し訳ありませんが、お力添えをいただければ幸いです。