我使用了以下示例http://matplotlib.org/1.4.1/examples/animation/simple_3danim.html
并修改了您的代码:
from matplotlib import pyplot as pltimport numpy as npimport mpl_toolkits.mplot3d.axes3d as p3from matplotlib import animationfig = plt.figure()ax = p3.Axes3D(fig)def gen(n): phi = 0 while phi < 2*np.pi: yield np.array([np.cos(phi), np.sin(phi), phi]) phi += 2*np.pi/ndef update(num, data, line): line.set_data(data[:2, :num]) line.set_3d_properties(data[2, :num])N = 100data = np.array(list(gen(N))).Tline, = ax.plot(data[0, 0:1], data[1, 0:1], data[2, 0:1])# Setting the axes propertiesax.set_xlim3d([-1.0, 1.0])ax.set_xlabel('X')ax.set_ylim3d([-1.0, 1.0])ax.set_ylabel('Y')ax.set_zlim3d([0.0, 10.0])ax.set_zlabel('Z')ani = animation.FuncAnimation(fig, update, N, fargs=(data, line), interval=10000/N, blit=False)#ani.save('matplot003.gif', writer='imagemagick')plt.show()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)