- 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 use matplotlib.animate to animate a contour plot in Python?
To animate a contour plot in matplotlib in Python, we can take the following steps−
- Create a random data of shape 10☓10 dimension.
- Create a figure and a set of subplots using subplots() method.
- Makes an animation by repeatedly calling a function *func* using FuncAnimation() class.
- To update the contour value in a function, we can define a method animate that can be used in FuncAnimation() class.
- To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.randn(800).reshape(10, 10, 8) fig, ax = plt.subplots() def animate(i): ax.clear() ax.contourf(data[:, :, i]) ani = animation.FuncAnimation(fig, animate, 5, interval=50, blit=False) plt.show()
Output
- Related Articles
- How to plot matplotlib contour?
- How to animate a scatter plot in Matplotlib?
- How to animate a line plot in Matplotlib?
- Contour Plot using Python Matplotlib
- How can Matplotlib be used to create 3 dimensional contour plot using Python?
- Contour hatching in Matplotlib plot
- How do you create a legend for a contour plot in Matplotlib?
- Plot Matplotlib 3D plot_surface with contour plot projection
- How to use an update function to animate a NetworkX graph in Matplotlib?
- How to approximate a contour shape in an image using OpenCV Python?
- How to a plot stem plot in Matplotlib Python?
- How to plot a graph in Python?
- Setting the limits on a colorbar of a contour plot in Matplotlib
- How to animate a pcolormesh in Matplotlib?
- How to plot a time series in Python?

Advertisements