【发布时间】:2015-01-09 15:00:07
【问题描述】:
我正在尝试使用 Matplotlib 的 FuncAnimation 为每帧动画显示一个点设置动画。
# modules
#------------------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as py
from matplotlib import animation
py.close('all') # close all previous plots
# create a random line to plot
#------------------------------------------------------------------------------
x = np.random.rand(40)
y = np.random.rand(40)
py.figure(1)
py.scatter(x, y, s=60)
py.axis([0, 1, 0, 1])
py.show()
# animation of a scatter plot using x, y from above
#------------------------------------------------------------------------------
fig = py.figure(2)
ax = py.axes(xlim=(0, 1), ylim=(0, 1))
scat = ax.scatter([], [], s=60)
def init():
scat.set_offsets([])
return scat,
def animate(i):
scat.set_offsets([x[:i], y[:i]])
return scat,
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=len(x)+1,
interval=200, blit=False, repeat=False)
很遗憾,最终的动画剧情与原版剧情不一样。在动画的每一帧中,动画情节也会闪烁几个点。关于如何使用animation 包正确设置散点图动画的任何建议?
【问题讨论】:
标签: python python-3.x numpy matplotlib