
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to pass arguments to animation.FuncAnimation() in Matplotlib?
To pass arguments to animation.FuncAnimation() for a contour plot in Matplotlib in Python, we can take the following steps −
- Create a random data of 10☓10 dimension.
- Create a figure and a set of subplots using subplots() method.
- Make an animation by repeatedly calling a function *func* using FuncAnimation() class
- To update the contour value in the 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.50, 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 pass arguments to anonymous functions in JavaScript?
- How to pass arguments in Invoke-Command in PowerShell?
- How to pass arguments to a Button command in Tkinter?
- How to pass arguments by value in Python function?
- How to pass arguments by reference in Python function?
- How to pass arrays as function arguments in JavaScript?
- How to Pass Command Line Arguments to Bash Script
- How to pass arguments by reference in a Python function?
- Pass arguments from array in PHP to constructor
- How to pass command line arguments to a python Docker container?
- How to pass individual members of structure as arguments to function in C language?
- How to pass the individual members as arguments to function using structure elements?
- Python Program to pass the tuple as function arguments
- How can I pass arguments to Tkinter button's callback command?
- Java Program to pass method call as arguments to another method

Advertisements