1
私は、file.txtからデータを取得する3Dアニメーショングラフをプロットしようとしています。私はプロット自体が更新されないtxtファイルに新しい座標を導入するときなど、アニメーション機能に問題があります。file.txtから3Dグラフをアニメーション化する
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
import math as m
import matplotlib.animation as animation
import time
np.set_printoptions(threshold=np.inf)
def animate(i):
point_stress=open(r'Prova.txt','r').read()
lines=point_stress.split('\n')
xs=[]
ys=[]
zs=[]
for line in lines:
if len(line)>1:
x,y,z=line.split()
x=float(x)
y=float(y)
z=float(z)
xs.append(x)
ys.append(y)
zs.append(z)
point_stress.close()
ax1.clear()
ax1.plot(xs,ys,zs)
fig=plt.figure()
ax1=fig.add_subplot(111,projection='3d')
ani=animation.FuncAnimation(fig,animate,interval=1000)
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax1.set_zlabel('z')
plt.show()
コードは以下の通りです。私は座標を追加し、同時にグラフを更新したいと思います。あなたのスクリプトでは、すべての座標がすでに書かれている必要があります。 –
どうすればいいですか? –