jupyter notebookを使用しての作業中です。
類似の質問・サイトが見受けられなかったため投稿します。
同じ3次元グラフ空間の中に2つ以上の点を決めた座標通りの軌道を描くアニメーションの作成をするためのコードを組んでいるのですが
1つなら問題なく動くのですが2つ以上の座標を指定しても1つしか表示されなくて困っています。
%matplotlib notebook %matplotlib nbagg from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import matplotlib.animation as animation from IPython.display import HTML import numpy as np n = 2 def init(): ax.set_xlim(-1000,1000) ax.set_ylim(-1000,1000) ax.set_zlim(0,1000) ax.set_xlabel("x") ax.set_ylabel("y") ax.set_zlabel("z") ax.set_aspect('equal') return lines x1,y1,z1 = [],[],[] x2,y2,z2 = [],[],[] x1=[ 1, 8, 3, 6, 3, 6, 4 ] y1=[ 9, 1, 5, 3, 7, 3, 8 ] z1=[ 0, 2, 5, 7, 1, 0, 5 ] a = [ x1, y1, z1 ] x2=[ 6, 3, 7, 4, 7, 2, 0 ] y2=[ 9, 6, 4, 6, 3, 5, 8 ] z2=[ 1, 7, 9, 5, 3, 7, 4 ] b = [ x2, y2, z2 ] def update_lines(num, data, lines,points): for dat,line, point in zip(data,lines, points): point.set_data(dat[0:2, num+1]) point.set_3d_properties(dat[2, num+1]) return lines # Attaching 3D axis to the figure fig = plt.figure() ax = fig.gca(projection='3d') # Lines to plot in 3D x = np.linspace(-3, 2, 30) y = np.linspace(-3, 2, 30) z = np.linspace(-3, 2, 30) x1, y1, z1 = x1, y1, z1#プロットするデータ x2, y2, z2 = x2, y2, z2#プロットするデータ data = np.array([a])#プロットするデータ data = np.array([b])#プロットするデータ lines=[ax.plot(dat[0, 0:1], dat[1, 0:1], dat[2, 0:1] )[0] for dat in data] points=[ax.plot(dat[0, :1], dat[0, :1], dat[0, :1], 'o-')[0] for dat in data] line_ani = animation.FuncAnimation(fig, update_lines, 172, fargs=(data,lines, points), interval=10, init_func=init, blit=True, repeat=True)
以上のコードを入力すると
bの点だけが動いて表示されます。
同時にaを同じ空間の中に表示させるにはどうしたらよいのでしょうか。
また、aとbを線で繋げたい場合は
points=[ax.plot(dat[0, :1], dat[0, :1], dat[0, :1], 'o-')[0] for dat in data]
のように'o-'にしていれば繋がるのでしょうか。
並行して教えていただければ幸いです。
あなたの回答
tips
プレビュー