美文网首页
Python-136 制作gif动画图并保存 2021-12-2

Python-136 制作gif动画图并保存 2021-12-2

作者: RashidinAbdu | 来源:发表于2021-12-28 16:20 被阅读0次
    • 具体代码与解释如下:
    #pip install matplotlib
    #pip install pillow
    import matplotlib.pyplot as plt
    import matplotlib.animation as anim
    from PIL import Image
    from glob import glob
    from matplotlib import animation
    
    fig, ax = plt.subplots(figsize=(3.6, 3.5))
    fig.subplots_adjust(bottom=0, top=1, left=0, right=1)
    ax.axis('off')
    
    ims = []
    for fname in sorted(glob('C:/Users/Rashidin Abdugheni/Pictures/wallpaper/simba.jpg')):
    # print(fname) # uncomment to follow loading of images
               im = ax.imshow(Image.open(fname), animated=True)
               ims.append([im])
    
    ani = anim.ArtistAnimation(fig, artists=ims, interval=113,repeat=True)
    # Uncomment to save as mp4 movie file. Need ffmpeg.
    # ani.save('pacb.mp4', writer='ffmpeg') # ffmpeg
    plt.show()
    ani.save('C:/Users/Rashidin Abdugheni/Pictures/wallpaper/Animation.gif', writer='pillow')
    
    

    得到的是:


    Animation.gif

    相关文章

      网友评论

          本文标题:Python-136 制作gif动画图并保存 2021-12-2

          本文链接:https://www.haomeiwen.com/subject/apbpqrtx.html