拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 使用Matplotlib制作影片

使用Matplotlib制作影片

白鹭 - 2022-01-23 2016 0 0

我正在尝试使用 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热心网友回复:

  1. 您需要为变量分配影片以防止其被洗掉

  2. 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 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *