python animation函数_未调用FuncAnimation更新函数

我不太了解如何创建一个类来制作数据动画。要点如下:import numpy as np

import matplotlib.pyplot as plt

import matplotlib.animation as animation

x = np.arange(100).reshape((100, 1))

y = np.random.randn(100, 1)

xy = np.hstack((x, y))

class PlotData:

def __init__(self):

fig, ax = plt.subplots()

fig.set_size_inches((11, 9))

self.fig = fig

self.ax = ax

self.ln0, = ax.plot([], [])

def init(self):

self.ln0.set_data([], [])

return(self.ln0, )

def update(self, frame_no):

data = xy[0:frame_no + 1]

self.ln0.set_data(data[:, 0], data[:, 1])

return(self.ln0, )

if __name__ == '__main__':

my_plot = PlotData()

anim = animation.FuncAnimation(my_plot.fig, my_plot.update,

init_func=my_plot.init, blit=True,

frames=99, interval=50)

plt.show()

这只会产生init方法输出,而不会生成更新,因此最终会生成一个没有动画的空白绘图。怎么回事?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值