【发布时间】:2015-05-10 18:10:02
【问题描述】:
我创建了一个阶跃函数的 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),但值不是恒定的并且随着时间的推移而滚动,每一步都是动态的并且上下移动。如何更改我的代码以实现这种转变?
【问题讨论】:
-
我对您想要更改的内容有点困惑。您是说希望 x 轴值增加,以便更清晰地滚动?
-
@seaotternerd 是的,我认为这就是我想要的。目前,这些步骤看起来就像在原地上下移动,没有发生滚动。
标签: python animation matplotlib trigonometry