軌跡の描画(始点から終点までの変化;散布図)

Python

1import pandas as pd 2import matplotlib.pyplot as plt 3import numpy as np 4 5n = 30#学習回数#6 7dfs = [pd.read_table(f'/content/data_{i}.txt', sep=r'\s+', header=None, names=['z', 'y', 'x']).head(n) for i in range(1, 1601)]8 9plt.figure(figsize=[15, 15])10ax = plt.gca()11 12for df in dfs:13 14 df.iloc[1:-1].plot(x='x', y='y', kind='scatter', ax=ax,zorder=0.5)#変化過程#15 #df.iloc[[0,-1]].plot.line(x='x',y='y',ax=ax,marker='_',color='b',zorder=0.1,linewidth=0.5)#始点から終点の直線#16 plt.scatter(x=df.iloc[0]['x'], y=df.iloc[0]['y'],marker='o',color='gray',facecolor='#ffffff',zorder=0.1)#始点#17 plt.scatter(x=df.iloc[-1]['x'], y=df.iloc[-1]['y'],marker='+',color='r',s=100,zorder=1) #終点#18 plt.plot('x','y')19 20#凡例の除去#21#ax.get_legend().remove()22ax.grid(color='gray', linestyle=':')23 24axis_array = np.arange(-5, 5, step=1)25plt.xticks(np.arange(-5, 5, step=1))26 27axis_array = np.arange(-2.5, 2.5, step=1)28plt.yticks(np.arange(-2.5, 2.5, step=1))29 30plt.xlabel("x")31plt.ylabel("y")32plt.savefig("out.png")33 34plt.show()35 36

コメントを投稿

0 コメント