Try drawing a simple animation in Python

demo

output.gif

Method

Here, we use the ʻanimation.ArtistAnimation function of Python's graph drawing library [matplotlib](http://matplotlib.org/). As a flow, an array of drawing data (ʻims) is prepared, and the animation is drawn by passing the array to the second argument of the ʻanimation.ArtistAnimation` function.

demo.py


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

fig = plt.figure()
x = np.arange(0, 10, 0.1)

ims = []
for a in range(50):
    y = np.sin(x - a)
    im = plt.plot(x, y, "r")
    ims.append(im)
    
ani = animation.ArtistAnimation(fig, ims)
plt.show()

You can save the animation in gif format by adding ↓.

ani.save("hoge.gif")

reference

I tried scatter plot animation in python http://cflat-inc.hatenablog.com/entry/2014/03/17/214719

Recommended Posts

Try drawing a simple animation in Python
Implementing a simple algorithm in Python 2
Run a simple algorithm in Python
A simple HTTP client implemented in Python
Try sending a SYN packet in Python
Create a simple GUI app in Python
Write a simple greedy algorithm in Python
Write a simple Vim Plugin in Python 3
Try a functional programming pipe in Python
Try drawing a map with python + cartopy 0.18.0
Simple gRPC in Python
Graph drawing in python
Try gRPC in Python
Try 9 slices in Python
Set up a simple HTTPS server in Python 3
Try to calculate a statistical problem in Python
A simple Pub / Sub program note in Python
Create a simple momentum investment model in Python
Set up a simple SMTP server in Python
Take a screenshot in Python
Drawing candle charts in python
Create a function in Python
Create a dictionary in Python
Until drawing a 3D graph in Python on windows10
Make a simple Slackbot with interactive button in python
Try searching for a million character profile in Python
Try embedding Python in a C ++ program with pybind11
Try LINE Notify in Python
Make a bookmarklet in Python
Try implementing Yubaba in Python 3
Simple regression analysis in Python
Draw a heart in Python
Simple IRC client in python
Try running python in a Django environment created with pipenv
Try creating a Deep Zoom file format .DZI in Python
I made a simple typing game with tkinter in Python
A simple way to avoid multiple for loops in Python
Try building a neural network in Python without using a library
Try running a function written in Python using Fn Project
Just try to receive a webhook in ngrok and python
Maybe in a python (original title: Maybe in Python)
Write a binary search in Python
[python] Manage functions in a list
Hit a command in Python (Windows)
Try throwing a query in Redash
Simple OAuth 2 in Python (urllib + oauthlib)
Create a DI Container in Python
Drawing a silverstone curve using python
Draw a scatterplot matrix in python
Try implementing extension method in python
ABC166 in Python A ~ C problem
Write A * (A-star) algorithm in Python
Try using LevelDB in Python (plyvel)
Let's try Fizz Buzz in Python
Create a binary file in Python
Try to calculate Trace in Python
Try PLC register access in Python
Solve ABC036 A ~ C in Python
Write a pie chart in Python
Write a vim plugin in Python
Write a depth-first search in Python