我正在创建一个Matplotlib步进函数的动画。我正在使用以下代码...
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, = ax.step([], [])
def init():
line.set_data([], [])
return line,
def animate(i):
x = np.linspace(0, 2, 10)
y = np.sin(2 * np.pi * (x - 0.01 * i))
line.set_data(x, y)
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=100, interval=20, blit=True)
plt.show()
它有点类似于我想要的东西(类似下面的gif),但是不同的是,值不是恒定的并随时间滚动,而是每个步骤都是动态的并上下移动。我该如何更改我的代码以实现这种移位?