Happy Diwali and learn a simple way to create animation with python


Colorful lights, delicious sweets, and sparkling crackers. That’s Diwali. Kids are so happy. Can’t describe the joy in their eyes!!!

Well to end the day, here’s a super simple python animation to celebrate Diwali.

Wish you Happy Diwali!

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

def update_line(i,data,dx,line):
    data +=dx
    return line,

dx = np.random.rand(2, 500)
data = np.random.rand(2, 500)*-3
fig = plt.figure()

line, = plt.plot([], [], 'r*')
ax = fig.add_subplot(111)

plt.xlim(-3, 6)

fig.suptitle('H a p p y    D i w a l i', fontsize=20)
line_ani = animation.FuncAnimation(fig, update_line,fargs=(data,dx, line),
interval=50, blit=False)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s