Skip to main content

Easy matplotlib animation.

Project description

celluloid

Build Status codecov

Easy Matplotlib Animation

Creating animations should be easy. This module makes it easy to adapt your existing visualization code to create an animation.

Install

pip install celluloid

Manual

Follow these steps:

  1. Create a matplotlib Figure and create a Camera from it:
from celluloid import Camera
fig = plt.figure()
camera = Camera(fig)
  1. Reusing the figure and after each frame is created, take a snapshot with the camera.
plt.plot(...)
plt.fancy_stuff()
camera.snap()
  1. After all frames have been captured, create the animation.
animation = camera.animate()
animation.save('animation.mp4')

The entire module is less than 50 lines of code.

Examples

Minimal

As simple as it gets.

import numpy as np
from matplotlib import pyplot as plt
from celluloid import Camera

fig = plt.figure()
camera = Camera(fig)
for i in range(10):
    plt.plot([i] * 10)
    camera.snap()
animation = camera.animate()

Subplots

Animation at the top.

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 np.linspace(0, 2 * np.pi, 128, endpoint=False):
    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()

Credits

Inspired by plotnine.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

celluloid-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

celluloid-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file celluloid-0.1.0.tar.gz.

File metadata

  • Download URL: celluloid-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.20.0

File hashes

Hashes for celluloid-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d99a1848d2d64e78eb14aa0bbe2ae3b1376725352abe8bf0a6a750a0a026b290
MD5 cc1e59a4d23048e2e90e7e913b60a1f4
BLAKE2b-256 9a5998615244ae0bcdb31d94beb8b95e50dc07727462671f3458ef4f17666358

See more details on using hashes here.

File details

Details for the file celluloid-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: celluloid-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.20.0

File hashes

Hashes for celluloid-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 274f1835a497c6c990583c43dceb20a16c7f89b3d681ecfff604284e9213be15
MD5 9fdadb462a3ea3647afa3bb133cae4f0
BLAKE2b-256 711f42fedd7e81151cbc81d74967da2f25125e99aeccb3c8906c1a5b40e68f63

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page