0

I want to make an animation of a drum vibration in python. My problem is that the zero point of the z_axis keeps moving. How can I freeze the z_axis? video link

fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

z=sol[0]

def init():
    surf,=ax.plot_surface(xv,yv,z0)
    ax.set_xlim(0,1)
    ax.set_ylim(0,1)
    #ax.set_zlim3d(-1,1)
    ax.set_zlim(-1,1)
    return surf
def animate(i):
    u=add_boundry(z[i+1])
    ax.clear()
    surf=ax.plot_surface(xv, yv, u)
    return surf


    
anim = FuncAnimation(fig, animate,frames=200, interval=200, blit=False)


anim.save('drum.gif', writer='ffmpeg')
afshin
  • 1

1 Answers1

0

I find a solution.

fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
z=sol[0]
z0=add_boundry(z[0])
#surf=ax.plot_surface(np.empty_like(xv),np.empty_like(yv),np.empty_like(z0))

def init():
    surf=ax.plot_surface(xv,yv,z0)
    ax.set_xlim(0,1)
    ax.set_ylim(0,1)
    ax.set_zlim(-0.2,0.2)
    ax._autoscaleZon = False
    return surf
def animate(i):
    u=add_boundry(z[i+1])
    ax.clear()
    surf=ax.plot_surface(xv, yv, u)
    ax.set_xlim(0,1)
    ax.set_ylim(0,1)
    ax.set_zlim(-0.2,0.2)
    ax._autoscaleZon = False
    return surf


    
anim = FuncAnimation(fig, animate, init_func=init, frames=200, interval=200, blit=False)


anim.save('drum.gif', writer='ffmpeg')
afshin
  • 1