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, 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

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.4.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file gif-1.0.4.tar.gz.

File metadata

  • Download URL: gif-1.0.4.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7

File hashes

Hashes for gif-1.0.4.tar.gz
Algorithm Hash digest
SHA256 f93856bd17edb3c473d3a533f4b1e44eee3d3d31015506a76e0367ba3eb3da6e
MD5 edd5ec357d61cdd18d24388d4a2b618f
BLAKE2b-256 e803d80590240732c9c05a8ad19946313578a9884a789ff927e6f8bf3a99a37f

See more details on using hashes here.

Provenance

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