【发布时间】:2019-04-24 17:15:35
【问题描述】:
我有一个像这样的简单动画情节:
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/ 中的子图之一一样扩展,其中 x 轴动态扩展以容纳传入的数据点。
我该如何做到这一点?
【问题讨论】:
-
在使用 blitting 时不能这样做。但是如果你关闭它,你可以使用
ax.set_xlim(newxmin, newxmax)来改变你的动画函数的限制。 -
@ImportanceOfBeingErnest 太棒了,谢谢,成功了! :)
标签: python python-3.x animation matplotlib