from matplotlib import pyplot as plt
from celluloid import Camera

## minimal
fig = plt.figure()
camera = Camera(fig)
for i in range(10):
    plt.plot([i] * 10)
    camera.snap()
animation = camera.animate()
animation.save('celluloid_minimal.gif', writer = 'imagemagick')

# subplot:
#import numpy as np
#from matplotlib import pyplot as plt
#from celluloid import Camera
#
#fig, axes = plt.subplots(2)
#camera = Camera(fig)
#t = np.linspace(0, 2 * np.pi, 128, endpoint=False)
#for i in t:
#    axes[0].plot(t, np.sin(t + i), color='blue')
#    axes[1].plot(t, np.sin(t - i), color='blue')
#    camera.snap()
#    
#animation = camera.animate()  
#animation.save('celluloid_subplots.gif', writer = 'imagemagick')


## lengend
#import matplotlib
#from matplotlib import pyplot as plt
#from celluloid import Camera
#
#fig = plt.figure()
#camera = Camera(fig)
#for i in range(20):
#    t = plt.plot(range(i, i + 5))
#    plt.legend(t, [f'line {i}'])
#    camera.snap()
#animation = camera.animate()
#animation.save('celluloid_legends.gif', writer = 'imagemagick')
