- 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
Plotting animated quivers in Python using Matplotlib
To animate quivers in Python, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create x and y data points using numpy.
- Create u and v data points using numpy.
- Create a figure and a set of subplots.
- Plot a 2D field of arrows using quiver() method.
- To animate the quiver, we can change the u and v values, in animate() method. Update the u and v values and the color of the vectors.
- To display the figure, use show() method.
Example
import numpy as np import random as rd from matplotlib import pyplot as plt, animation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x, y = np.mgrid[:2 * np.pi:10j, :2 * np.pi:5j] u = np.cos(x) v = np.sin(y) fig, ax = plt.subplots(1, 1) qr = ax.quiver(x, y, u, v, color='red') def animate(num, qr, x, y): u = np.cos(x + num * 0.1) v = np.sin(y + num * 0.1) qr.set_UVC(u, v) qr.set_color((rd.random(), rd.random(), rd.random(), rd.random())) return qr, anim = animation.FuncAnimation(fig, animate, fargs=(qr, x, y), interval=50, blit=False) plt.show()
Output
- Related Articles
- Plotting profile histograms in Python Matplotlib
- Plotting a masked surface plot using Python, Numpy and Matplotlib
- Plotting Pandas DataFrames in Pie Charts using Matplotlib
- Plotting grids across the subplots in Python Matplotlib
- Plotting a cumulative graph of Python datetimes in Matplotlib
- Plotting multiple line graphs using Pandas and Matplotlib
- Interactive plotting with Python Matplotlib via command line
- How to deal with NaN values while plotting a boxplot using Python Matplotlib?
- Plotting graph using seaborn in python.
- Plotting with seaborn using the matplotlib object-oriented interface
- Adding extra contour lines using Matplotlib 2D contour plotting
- Geographical plotting using Python plotly
- Plot animated text on the plot in Matplotlib
- Plotting power spectral density in Matplotlib
- Plotting error bars from a dataframe using Seaborn FacetGrid (Matplotlib)

Advertisements