arrays - Python: Issue with animation from 3D matrix -


i´ve tried run following code:

import matplotlib.pyplot plt import numpy np import matplotlib.animation animation mpl_toolkits.mplot3d import axes3d matplotlib import cm #color map  u = np.array([[[0,0,0],[0,1,0],[0,0,0]],[[0,0,0],[0,2,0],[0,0,0]],[[0,0,0],[0,3,0],[0,0,0]]]) x = [-1,0,1] y = [-1,0,1] x,y = np.meshgrid(x,y)  fig = plt.figure() ax = axes3d.axes3d(fig)  def update(i, ax, fig):     ax.cla()     wframe = ax.plot_surface(x, y, u[:,:,i],rstride=1,cstride=1,cmap=cm.coolwarm)     ax.set_zlim3d(-1,1)     print("step= ",i)     return wframe  ani = animation.funcanimation(fig,update,frames=3,fargs=(ax, fig),interval=1000) ani.save('ani.mp4',bitrate=-1,codec="libx264") 

the animation is, however, not functioning - takes 2 times prime step (i=0) , then, looping on over again. can please me issue?

added init function , repeat=false

import matplotlib.pyplot plt import numpy np import matplotlib.animation animation mpl_toolkits.mplot3d import axes3d matplotlib import cm #color map  u = np.array([[[0,0,0],[0,1,0],[0,0,0]],[[0,0,0],[0,2,0],[0,0,0]],[[0,0,0],[0,3,0],[0,0,0]]]) x = [-1,0,1] y = [-1,0,1] x,y = np.meshgrid(x,y)  fig = plt.figure() ax = axes3d.axes3d(fig)  def init():     wframe = ax.plot_surface([], [], [], rstride=1, cstride=1, cmap=cm.coolwarm)     return wframe  def update(i, ax, fig):     ax.cla()     wframe = ax.plot_surface(x, y, u[:,:,i],rstride=1,cstride=1,cmap=cm.coolwarm)     ax.set_zlim3d(-1,1)     print("step= ",i)     return wframe  ani = animation.funcanimation(fig,update,init_func=init, frames=3,fargs=(ax, fig),interval=1000,repeat=false) plt.show() 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -