The animation function must return a sequence of Artist objects.

常见报错

动画中plt.text, plt.title内容不会随时间更新

报错  The animation function must return a sequence of Artist objects.

update函数只能返回plt.gca().images, 不能返回plt, 否则会报错如上

原因&解决方法

上述问题都是因为 animation.FuncAnimation 函数中blit参数值设置成为了true, 在此情况下, blit会使动画开启优化, 只更新update中返回的部分, 如果我们不在update中主动返回多个对象, 就会报错“ The animation function must return a sequence of Artist objects.”, 即使我们返回了plt.gca().images取消了上述报错, 动画还是不会更新我们的plt.title & plt.text内容, 要想更新此内容, 必须返回上述两者对象, 示例如下:

# 更新函数
def update(frame):
    global angle
    plt.clf()  
    both_all = both_newtown_and_michellson(X, Y, frame)
    im = plt.imshow(both_all, cmap=black_to_yellow, extent=(-10, 10, -10, 10), alpha=0.5, vmin=-1, vmax=1)
    
    # 更新标题和文本
    title_text = plt.title(f'非等厚非等倾°')
    text = plt.text(0.023, 0.01, f'非等厚非等倾, θ = {angle:.6f} °', fontsize=12, color='red')
    
    plt.axis('off')
    
    # 返回更新的对象
    return [im, title_text, text]  #返回所有需要改变的值

参考博客

相同问题博客链接:动画函数必须返回Artist对象序列-腾讯云开发者社区-腾讯云 (tencent.com)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值