如何在numpy中为3d对象设置动画

时间:2013-05-29 15:38:49

标签: python numpy matplotlib

我有以下代码:

import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3
from matplotlib import animation

fig = plt.figure()
p3.autoscale = True
ax = p3.Axes3D(fig)
ax.grid(True)
ax.set_xlim(-100, 100)
ax.set_ylim(-100, 100)
ax.set_zlim(-100, 100)

u = np.r_[0:2*np.pi:100j]
v = np.r_[0:np.pi:100j]

scale = 15
x = scale * np.outer(np.cos(u),np.sin(v))
y = scale * np.outer(np.sin(u),np.sin(v))
z = scale * np.outer(np.ones(np.size(u)),np.cos(v))

Line3DCollection_1 = ax.plot_wireframe(x,y,z, rstride=50, cstride=50)
Line3DCollection_2 = ax.plot_wireframe(x + 50,y,z, rstride=50, cstride=50)

# initialization function: plot the background of each frame
def init():
    return Line3DCollection_1,
def animate(i):
    print("frame :"  + str(i))
    x = 50 * np.sin(np.radians(i))
    y = 50 * np.cos(np.radians(i))
    path = plt.plot([x],[y],[0], 'bo')
    return path

# call the animator.  blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=360, interval=0.1, blit=True)
plt.show()

这将生成2个球体和一个我希望其中一个球体可以采用的路径,但我不确定如何在动画中包含它,我可以为路径设置动画,但不能为“Line3DCollection_2”球体设置动画。 / p>

有没有人有任何想法? 感谢。

0 个答案:

没有答案