Skip to content
Better animated Matplotlib gifs
Python
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
logo logo tweak Feb 1, 2020
tests travis Jan 30, 2020
.gitignore
.travis.yml travis on tags Feb 1, 2020
LICENSE Initial commit Jan 30, 2020
README.md Update README.md Feb 1, 2020
gif.py travis Jan 30, 2020
setup.py bump Feb 1, 2020

README.md

gif

GitHub Travis PyPI Downloads

About

gif is a better way to build animated Matplotlib gifs.

Installation

pip install -U gif

Usage

gif is easy to use. Just import:

import gif
from matplotlib import pyplot as plt

Decorate a Matplotlib plot function with gif.frame:

@gif.frame
def plot(x, y):
    plt.figure(figsize=(5, 3), dpi=100)
    plt.scatter(x, y)
    plt.xlim((0, 100))
    plt.ylim((0, 100))

Build a bunch of "frames" with a standard for loop:

from random import randint

frames = []
for _ in range(50):
    x = [randint(0, 100) for _ in range(10)]
    y = [randint(0, 100) for _ in range(10)]
    frame = plot(x, y)
    frames.append(frame)

Select the duration (milliseconds) between each frame and save:

gif.save(frames, "examples/chaos.gif", duration=100)

Examples

Chaos (code):

chaos.gif

Preferential Attachment (code, theory):

attachment.gif

Wave (code, original):

wave.gif

Hypothetical Outcome Plot (code, original):

hop.gif

Polar Plot (code, data, inspiration):

canada.gif

Tornado (code, inspiration):

tornado.gif

You can’t perform that action at this time.