- 具体代码与解释如下:
#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
网友评论