我正在嘗試使用 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()
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/389342.html
標籤:Python matplotlib 图形
上一篇:matplotlib中的棱鏡
