• matplotlib_200730系列---14、Animation 动画


    matplotlib_200730系列---14、Animation 动画

    一、总结

    一句话总结:

    ani=animation.FuncAnimation(fig=fig,func=animate,frames=100,init_func=init,interval=20,blit=False)
    import numpy as np
    from matplotlib import pyplot as plt
    from matplotlib import animation
    
    # Create a figure and a set of subplots.
    fig,ax=plt.subplots()
    x=np.arange(0,2*np.pi,0.01)
    # print(x)
    line,=ax.plot(x,np.sin(x))
    # print(line)
    
    # 动画
    def animate(i): 
        line.set_ydata(np.sin(x+i/100))
        return line,
    
    # 初始化页面
    def init(): 
        line.set_ydata(np.sin(x))
        return line,
    
    # frames=100 帧
    # interval=20 ms
    # blit=False 整张图全部更新blit的值就是false,只更新修改点值就是true
    ani=animation.FuncAnimation(fig=fig,func=animate,frames=100,
                                init_func=init,interval=20,blit=False)
    
    plt.show()

    1、jupyter notebook matplotlib绘制动态图不能显示怎么办?

    引入pylab库,加上%pylab就可以画出动态库了:Using matplotlib backend: Qt5Agg
    from matplotlib import pylab
    %pylab
    
    Using matplotlib backend: Qt5Agg
    Populating the interactive namespace from numpy and matplotlib

    二、Animation 动画

    博客对应课程的视频位置:

    In [5]:
    from matplotlib import pylab
    # 加了这句话,即可在jupyter notebook中显示动态图
    %pylab
    
    Using matplotlib backend: Qt5Agg
    Populating the interactive namespace from numpy and matplotlib
    
    In [6]:
    import numpy as np
    from matplotlib import pyplot as plt
    from matplotlib import animation
    
    fig,ax=plt.subplots()
    x=np.arange(0,2*np.pi,0.01)
    line,=ax.plot(x,np.sin(x))
    
    def animate(i): 
        line.set_ydata(np.sin(x+i/100))
        return line,
    
    def init(): 
        line.set_ydata(np.sin(x))
        return line,
    
    ani=animation.FuncAnimation(fig=fig,func=animate,frames=100,
                                init_func=init,interval=20,blit=False)
    
    plt.show()
    
    In [ ]:
     
     
    我的旨在学过的东西不再忘记(主要使用艾宾浩斯遗忘曲线算法及其它智能学习复习算法)的偏公益性质的完全免费的编程视频学习网站: fanrenyi.com;有各种前端、后端、算法、大数据、人工智能等课程。
    博主25岁,前端后端算法大数据人工智能都有兴趣。
    大家有啥都可以加博主联系方式(qq404006308,微信fan404006308)互相交流。工作、生活、心境,可以互相启迪。
    聊技术,交朋友,修心境,qq404006308,微信fan404006308
    26岁,真心找女朋友,非诚勿扰,微信fan404006308,qq404006308
    人工智能群:939687837

    作者相关推荐

  • 相关阅读:
    MongoDB结构划分
    iphone下scrollview图片浏览器小记
    图文详解linux/windows mysql忘记root密码解决方案
    【记】Javascript遍历对象属性的方法
    【jQuery】jQueryUI中的datepicker在overflow下的两点点小小的问题。
    第一个测试文章
    【记】Javascript的正则表达式RegExp
    【记】IE下input标签中的paddingleft和paddingright
    【CSS】关于IE、FireFox中table强制换行的总结
    【DOCTYPE】兼容模式和标准模式
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/13407576.html
Copyright © 2020-2023  润新知