I wrote this code to plot the quantum harmonic oscillator wave functions and potential
<code>x_0 = np.linspace(-10, 10, 500)
fig = plt.figure()
ax1 = plt.subplot(1, 1,1)
ax1.set_xlim(-10, 10)
ax1.set_ylim(0, 6)
ax1.set_xlabel('x')
ax1.set_ylabel('$|Psi|^2$')
line1, = ax1.plot([], [], "r-")
line2, = ax1.plot([], [])
def init():
line1.set_data(x_0, x_0**2)
return line1,
def animate(i):
line2.set_data(x_0 , wf_list[i])
return line1,
ani = animation.FuncAnimation(fig, animate, frames=len(wf_list),
init_func=init, blit=True,
interval=1)
</code>
<code>x_0 = np.linspace(-10, 10, 500)
fig = plt.figure()
ax1 = plt.subplot(1, 1,1)
ax1.set_xlim(-10, 10)
ax1.set_ylim(0, 6)
ax1.set_xlabel('x')
ax1.set_ylabel('$|Psi|^2$')
line1, = ax1.plot([], [], "r-")
line2, = ax1.plot([], [])
def init():
line1.set_data(x_0, x_0**2)
return line1,
def animate(i):
line2.set_data(x_0 , wf_list[i])
return line1,
ani = animation.FuncAnimation(fig, animate, frames=len(wf_list),
init_func=init, blit=True,
interval=1)
</code>
x_0 = np.linspace(-10, 10, 500)
fig = plt.figure()
ax1 = plt.subplot(1, 1,1)
ax1.set_xlim(-10, 10)
ax1.set_ylim(0, 6)
ax1.set_xlabel('x')
ax1.set_ylabel('$|Psi|^2$')
line1, = ax1.plot([], [], "r-")
line2, = ax1.plot([], [])
def init():
line1.set_data(x_0, x_0**2)
return line1,
def animate(i):
line2.set_data(x_0 , wf_list[i])
return line1,
ani = animation.FuncAnimation(fig, animate, frames=len(wf_list),
init_func=init, blit=True,
interval=1)
But for some reason the plot is only showing the potential and the animation is not working, any advice on where the issue is?
The wf_list is an array with the size of 315, and each element is an array itself with the size of 500, i.e the wave function at different times.