- 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 pcolormesh in Matplotlib?
To animate pcolormesh in matplotlib, we can take the following steps −
Create a figure and a set of subplots.
Create x, y and t data points using numpy.
Create X3, Y3 and T3, return coordinate matrices from coordinate vectors using meshgrid.
Create a pseudocolor plot with a non-regular rectangular grid using pcolormesh() method.
Make a colorbar with colormesh axis.
Animate pcolormesh using Animation() class method.
To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt, animation plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() x = np.linspace(-3, 3, 91) t = np.linspace(0, 25, 30) y = np.linspace(-3, 3, 91) X3, Y3, T3 = np.meshgrid(x, y, t) sinT3 = np.sin(2 * np.pi * T3 / T3.max(axis=2)[..., np.newaxis]) G = (X3 ** 2 + Y3 ** 2) * sinT3 cax = ax.pcolormesh(x, y, G[:-1, :-1, 0], vmin=-1, vmax=1, cmap='Blues') fig.colorbar(cax) def animate(i): cax.set_array(G[:-1, :-1, i].flatten()) anim = animation.FuncAnimation(fig, animate, interval=100, frames=len(t) - 1) anim.save('517.gif') plt.show()
Output
- Related Articles
- How to get smooth interpolation when using pcolormesh (Matplotlib)?
- How to animate text 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 the colorbar in Matplotlib?
- How to animate 3D plot_surface in Matplotlib?
- How to animate a time-ordered sequence of Matplotlib plots?
- How to animate a Seaborn heatmap or correlation matrix(Matplotlib)?
- Animate a rotating 3D graph in Matplotlib
- How to use an update function to animate a NetworkX graph in Matplotlib?
- How to use matplotlib.animate to animate a contour plot in Python?
- How to animate buttons using CSS?
- How to animate scrollLeft using jQuery?
- How to Animate Bullets in Lists using CSS

Advertisements