我有一个简单的动画情节,如下所示:
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(xlim=(0, 100), ylim=(0, 100))
line, = ax.plot([], [], lw=2)
x = []
y = []
# initialization function: plot the background of each frame
def init():
line.set_data([], [])
return line,
# animation function. This is called sequentially
def animate(i):
x.append(i + 1)
y.append(10)
line.set_data(x, y)
return line,
# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=200, interval=20, blit=True)
plt.show()
现在,这工作正常,但我希望它像这里的子图之一一样扩展http://www.roboticslab.ca/matplotlib-animation/ http://www.roboticslab.ca/matplotlib-animation/其中 x 轴动态延伸以容纳传入的数据点。
我该如何实现这个目标?
我遇到了这个问题(但对于 set_ylim ),我对 @ImportanceOfBeingErnest 的评论进行了一些尝试和错误,这就是我得到的,适应@nz_21问题。
def animate(i):
x.append(i + 1)
y.append(10)
ax.set_xlim(min(x), max(x)) #added ax attribute here
line.set_data(x, y)
return line,
# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=500, interval=20)
其实在网络上quoted http://www.roboticslab.ca/wp-content/uploads/2012/11/robotics_lab_animation_example.txt@nz_21 有一个类似的解决方案。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)