我正在尝试使用 MatPlotLib 在 Python 中创建影片。但是,我不知道我的以下代码有什么问题。它正在生成一个空白影像。
from matplotlib import pyplot as plt
import matplotlib.animation as animation
domain = [0., 1., 2.]
images = [[0., 0., 0.],
[1., 1., 1.],
[2., 2., 2.]]
figure = plt.figure()
axes = plt.axes()
graph = axes.plot([])
def set_frame(image):
graph.set_data(domain, image)
return graph
animation.FuncAnimation(figure, set_frame, frames=images)
plt.ylim(0., 2.)
plt.show()
uj5u.com热心网友回复:
您需要为变量分配影片以防止其被洗掉
graph
是您需要检索元素的串列
from matplotlib import pyplot as plt
import matplotlib.animation as animation
domain = [0., 1., 2.]
images = [[0., 0., 0.],
[1., 1., 1.],
[2., 2., 2.]]
figure = plt.figure()
axes = plt.axes()
graph = axes.plot([])
def set_frame(image):
graph[0].set_data(domain, image)
return graph
_ = animation.FuncAnimation(figure, set_frame, frames=images)
plt.ylim(0., 2.)
plt.show()
0 评论