我目前需要有关如何从 csv 更新 3D 颤动头值的帮助,我有一个 csv 文件,其中包含 3 列 x、y、z 轴,我想在我的 python 代码中更新为 u、v、w 变量。
我面临的问题是结果动画没有正确设置动画。这是一张静态图片,如下图所示。
https://i.stack.imgur.com/Os8FX.png
我确定我一定搞砸了如何迭代/读取 csv 数据文件。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.animation import FuncAnimation
fig, ax = plt.subplots(subplot_kw=dict(projection="3d"))
# Reading the data from a CSV file using pandas
repo = pd.read_csv('test.csv',sep=',',header=0)
data = np.array((repo['x'].values, repo['y'].values, repo['z'].values))
def get_arrow():
x = 0
y = 0
z = 0
u = data[0][:]
v = data[1][:]
w = data[2][:]
return x,y,z,u,v,w
quiver = ax.quiver(0,0,0,0,0,0)
ax.set_xlim(-.5, .5)
ax.set_ylim(-.5, .5)
ax.set_zlim(-.5, .5)
def update(theta):
global quiver
quiver.remove()
quiver = ax.quiver(*get_arrow())
ani = FuncAnimation(fig, update, frames=np.linspace(0,2*np.pi,200), interval=50)
plt.show()