#官网示例
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.colors import hsv_to_rgb
from celluloid import Camera
fig = plt.figure()
camera = Camera(fig)
for a in np.linspace(0, 2 * np.pi, 30, endpoint=False):
x = np.linspace(-3, 3, 800)
X, Y = np.meshgrid(x, x)
x = X + 1j * Y
y = (x ** 2 - 2.5) * (x - 2.5 * 1j) * (x + 2.5 * 1j) \
* (x - 2 - 1j) ** 2 / ((x - np.exp(1j * a)) ** 2
* (x - np.exp(1j * 2 * a)) ** 2)
H = np.angle(y) / (2 * np.pi) + .5
r = np.log2(1. + np.abs(y))
S = (1. + np.abs(np.sin(2. * np.pi * r))) / 2.
V = (1. + np.abs(np.cos(2. * np.pi * r))) / 2.
rgb = hsv_to_rgb(np.dstack((H, S, V)))
plt.imshow(rgb)
camera.snap()
animation = camera.animate()
animation.save('示例.gif')
参数介绍
interval(int,default: 200)帧之间延迟(单位毫秒)
repeat (True、False,default:True)播放完是否重复
repeat_delay (int,default:0)重复间隔
from celluloid import Camera
from matplotlib import pyplot as plt
fig = plt.figure()
camera = Camera(fig)
for i in range(0,10):
for j in range(0,10):
data = np.zeros((10,10))
data[i,j] = 1
plt.imshow(data)
camera.snap()
animation = camera.animate(interval=100,blit=True)
animation.save('示例1.gif')