Skip to main content

✨ Better animated Matplotlib gifs

Project description

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, 5))
    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, 'random.gif', duration=100)

Examples

Chaos (code):

Preferential Attachment (code, theory):


Wave (code, original):



Hypothetical Outcome Plot (code, original):



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

gif-1.0.2.tar.gz (2.6 kB view hashes)

Uploaded Source

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