我正在尝试在不使用 FuncAnimation的情况下使用matplotlib制作动画,因为它会导致 HTML (ffmpeg) 出现问题。我现在正在尝试使用哪个更常用于现场情节。plt.ion()
我制作动画没有问题,但曲线并没有真正移动,大部分时间都是边界在移动。
我尝试了通常的界限,比如 setplt.xlim(#boundaries)和 for the y... 但它没有用。关于如何解决问题的任何线索?
这是我所做的(这只是示例代码,因为我想做的动画是量子波函数,而代码已经有点乱了)
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
a = int(input("render level = "))
tmax = float(input("tmax = "))
x = np.linspace(0, 2*np.pi, a)
t = np.linspace(0, tmax, a)
plt.figure()
plt.ion()
plt.xlim([0, 2*np.pi])
plt.ylim([-1.2, 1.2])
plt.plot([], [])
i = 0
while i<a:
y = np.cos(t[i])*np.sin(x)
print(t[i])
plt.clf()
plt.plot(x, y)
plt.pause(1/(a*tmax))
i = i + 1
