- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Animation using Matplotlib with subplots and ArtistAnimation
To animate using Matplotlib with subplots and ArtistAnimation, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a figure and a set of subplots.
- Create a user-defined function, Init, to draw a clear frame.
- Use FuncAnimation to make an animation by repeatedly calling a function *func*.
- Define an animate function to update the data points in FuncArtist class.
- To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() xdata, ydata = [], [] ln, = plt.plot([], [], 'r*') def init(): ax.set_xlim(0, 100) ax.set_ylim(-1, 1) return ln, def animate(frame): xdata.append(frame) ydata.append(np.sin(frame)) ln.set_data(xdata, ydata) return ln, ani = FuncAnimation(fig, animate, init_func=init, blit=True, frames=100) plt.show()
Output
- Related Articles
- Annotate Subplots in a Figure with A, B, C using Matplotlib
- Creating 3D animation using matplotlib
- Animation with contours in matplotlib
- How to update the plot title with Matplotlib using animation?
- Row and column headers in Matplotlib's subplots
- Populating Matplotlib subplots through a loop and a function
- How to set same scale for subplots in Python using Matplotlib?
- How to increase the spacing between subplots in Matplotlib with subplot2grid?
- Updating the X-axis values using Matplotlib animation
- How to make more than 10 subplots in a figure using Matplotlib?
- Embedding small plots inside subplots in Matplotlib
- Manipulation on vertical space in Matplotlib subplots
- Manipulation on horizontal space in Matplotlib subplots
- Draw a border around subplots in Matplotlib
- How to zoom subplots together in Matplotlib/Pyplot?

Advertisements