Giter VIP home page Giter VIP logo

gif's Introduction

gif

GitHub Travis PyPI Downloads

About

The extension for Altair, matplotlib, and Plotly animations.

Installation

gif is installed at the command line:

pip install -U gif

Depending on which flavour of gif you plan to use you'll likely need some additional dependencies:

pip install "gif[altair]"     
pip install "gif[matplotlib]"
pip install "gif[plotly]"

Note: gif[altair] uses Selenium, which requires a properly configured chromedriver or geckodriver.

Usage (Altair)

Imports and data:

import random
import altair as alt
import pandas as pd
import gif

df = pd.DataFrame({
    't': list(range(10)) * 10,
    'x': [random.randint(0, 100) for _ in range(100)],
    'y': [random.randint(0, 100) for _ in range(100)]
})

Decorate a plot function with gif.frame and return an Altair object:

@gif.frame
def plot(i):
    d = df[df['t'] == i]
    chart = alt.Chart(d).encode(
        x=alt.X('x', scale=alt.Scale(domain=(0, 100))),
        y=alt.Y('y', scale=alt.Scale(domain=(0, 100)))
    ).mark_circle()
    return chart

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

frames = []
for i in range(10):
    frame = plot(i)
    frames.append(frame)

Specify the duration between each frame and save:

gif.save(frames, 'example.gif', duration=100, unit="ms", between="frames")

Usage (matplotlib)

Imports and data:

import random
from matplotlib import pyplot as plt
import gif

x = [random.randint(0, 100) for _ in range(100)]
y = [random.randint(0, 100) for _ in range(100)]

(Optional) Set the dots per inch resolution to 300:

gif.options.matplotlib["dpi"] = 300

Decorate a plot function with gif.frame (and don't return anything):

@gif.frame
def plot(i):
    xi = x[i*10:(i+1)*10]
    yi = y[i*10:(i+1)*10]
    plt.scatter(xi, yi)
    plt.xlim((0, 100))
    plt.ylim((0, 100))

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

frames = []
for i in range(10):
    frame = plot(i)
    frames.append(frame)

Specify the duration of the entire gif:

gif.save(frames, 'example.gif', duration=3.5, unit="s", between="startend")

Usage (Plotly)

Imports and data:

import random
import plotly.graph_objects as go
import pandas as pd
import gif

df = pd.DataFrame({
    't': list(range(10)) * 10,
    'x': [random.randint(0, 100) for _ in range(100)],
    'y': [random.randint(0, 100) for _ in range(100)]
})

Decorate a plot function with gif.frame and return a Plotly figure:

@gif.frame
def plot(i):
    d = df[df['t'] == i]
    fig = go.Figure()
    fig.add_trace(go.Scatter(
        x=d["x"],
        y=d["y"],
        mode="markers"
    ))
    fig.update_layout(width=500, height=300)
    return fig

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

frames = []
for i in range(10):
    frame = plot(i)
    frames.append(frame)

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

gif.save(frames, 'example.gif', duration=100)

Gallery (Altair)

Click on any image to see the source code

covid.gif emoji.gif pyramid.gif
textbooks.gif wave.gif

Gallery (matplotlib)

Click on any image to see the source code

attachment.gif hop.gif phone.gif
seinfeld.gif attachment.gif love.gif
subplots.gif compare_2_features.gif train_test_split.gif

Gallery (Plotly)

Click on any image to see the source code

bubble.gif swirl.gif waterfall.gif

If you have a dope ass animation that you think should be in the Gallery, submit a PR!

gif's People

Contributors

huang-sh avatar maxhumber avatar musoke avatar sivakar94 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.