Animate multiple graphs with matplotlib

I wrote a sample to animate multiple shapes with matplotlib. If you do not draw the shape you want to move before the animation, an error will occur.

Sample code

#!/usr/local/bin/python3.5
# -*- coding: utf-8 -*-

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

fig = plt.figure(1)
ax = fig.add_subplot(111)

#Draw the initial state before animating
x = np.arange(0, 10, 0.1)
y = np.sin(x)
sin01, = ax.plot(y, 'b')
sin02, = ax.plot(y, 'g')

#Frame update
def update(i):
    sin01.set_ydata(np.sin(x-i))
    sin02.set_ydata(np.sin(x+i))

ani = animation.FuncAnimation(fig, update, 1000, blit=False, interval=100, repeat=False)
#ani.save('./animation.mp4')

plt.show()

result

animation.gif

Recommended Posts

Animate multiple graphs with matplotlib
Animate with matplotlib
[Python] How to draw multiple graphs with Matplotlib
Easy to draw graphs with matplotlib
How to title multiple figures with matplotlib
Display Japanese graphs with VS Code + matplotlib
Animation with matplotlib
Japanese with matplotlib
Animation with matplotlib
Histogram with matplotlib
Two ways to display multiple graphs in one image with matplotlib
[Python] Customize Colormap when drawing graphs with matplotlib
Multiple selections with Jupyter
2-axis plot with Matplotlib
Heatmap with Python + matplotlib
Band graph with matplotlib
Learn with Cheminformatics Matplotlib
Real-time drawing with matplotlib
Various colorbars with Matplotlib
3D plot with matplotlib
Overlay graphs with sympy
Adjust axes with matplotlib
(For those unfamiliar with Matplotlib) Tips for drawing graphs with Seaborn
Adjust the ratio of multiple figures with the matplotlib gridspec
Graph Excel data with matplotlib (1)
Use directional graphs with networkx
Draw multiple graphs using Pandas
Multiple regression analysis with Keras
Try using matplotlib with PyCharm
Embed matplotlib graphs in Tkinter
Graph drawing method with matplotlib
Manipulate multiple proxies with Squid
Multiple file processing with Kivy + Matplotlib + Draw Graph on GUI
Graph Excel data with matplotlib (2)
Dynamically generate graphs with matplotlib and embed in PDF with reporlab
Control multiple robots with jupyter-lab
Create plot animation with Python + Matplotlib
A python graphing manual with Matplotlib.
Inference & result display with Tensorflow + matplotlib
Japaneseize Matplotlib with Alpine using Docker
Launch multiple instances with Postgresql 11.x
Publish nice graphs online with plotly
Scraping multiple pages with Beautiful Soup
[Python] font family and font with matplotlib
Connect to multiple databases with SQLAlchemy
Draw Japanese with matplotlib on Ubuntu
Load multiple JavaScript files with PyWebView
Draw a loose graph with matplotlib
Versatile data plotting with pandas + matplotlib
Set multiple WSGIPythonPath with Apache + mod_wsgi
Post multiple Twitter images with python
Comment out multiple lines with csh
Extract specific multiple columns with pandas
Heatmap with Dendrogram in Python + matplotlib
Switch between multiple models with M5StickV
Easy Japanese font setting with matplotlib
Extract multiple elements with Numpy array
Multiple integrals with Python and Sympy
Continuously color with matplotlib scatter plot
Draw Lyapunov Fractal with Python, matplotlib
When matplotlib doesn't work with python2.7