- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
How to animate a time-ordered sequence of Matplotlib plots?
To animate a time-ordered sequence of Matplotlib plots, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a new figure or activate an existing figure.
- Add an axes to the figure as part of a subplot arrangement.
- Return the first recurrence after the given datetime instance using after() method.
- Write an animate() method to animate. Display the data as an image, i.e., on a 2D regular raster.
- To display the figure, use show() method.
Example
import numpy as np import matplotlib matplotlib.use('TkAgg') import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111) def animate(): data = np.random.randn(5, 5) im = plt.imshow(data, cmap="plasma") for i in np.arange(1, 100): data = np.random.randn(5, 5) im.set_data(data) fig.canvas.draw() win = fig.canvas.manager.window fig.canvas.manager.window.after(10, animate) plt.show()
Output
- Related Articles
- How to animate a pcolormesh in Matplotlib?
- How to animate a line plot in Matplotlib?
- How to animate a scatter plot in Matplotlib?
- How to animate a sine curve in Matplotlib?
- How to animate text in Matplotlib?
- How to reuse plots in Matplotlib?
- How to Annotate Matplotlib Scatter Plots?
- How to animate the colorbar in Matplotlib?
- How to animate 3D plot_surface in Matplotlib?
- How to display a sequence of images using Matplotlib?
- How to add annotations in Matplotlib Plots?
- How to save Matplotlib 3d rotating plots?
- How to animate a Seaborn heatmap or correlation matrix(Matplotlib)?
- How to clear the memory completely of all Matplotlib plots?
- How to make several plots on a single page using Matplotlib?

Advertisements