我正在尝试在Python中对向量(如风)进行动画处理。我尝试使用pylab中的quiver函数,并与matplotlib.animation结合使用。然而,结果显示'QuiverKey' object is not subscriptable
。我想这可能是因为我没有完全理解这两个函数之间的关系,或者只是这两个函数不匹配。以下是我的代码,实际上是来自于matplotlib中的quiver和animation函数的组合。
def update_line(num, data, line):
line.set_data(data[...,:num])
return line,
X,Y = np.meshgrid(np.arange(0,2*np.pi,.2),np.arange(0,2*np.pi,.2) )
U = np.cos(X)
V = np.sin(Y)
fig1 = plt.figure()
Q = quiver( X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
pivot='mid', color='r', units='inches' )
data = quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'})
plt.axis([-1, 7, -1, 7])
title('scales with plot width, not view')
l, = plt.plot([], [], 'r-')
plt.xlabel('x')
plt.ylabel('y')
plt.title('test')
line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l),
interval=50, blit=True)
plt.show()
Q.set_UVC()
来更新箭头向量。 - ali_m