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()
코드는 다음과 같다. 좌표를 추가하고 동시에 그래프를 업데이트하고 싶습니다. 스크립트로 모든 좌표가 이미 작성되어 있어야합니다. –
어떻게 할 수 있습니까? –