Quiver Plot using meshgrid
A quiver plot containing two arrows is a good start, but it is too slow and too long to add arrows to the quiver plot one by one.So to create a fully 2D surface of arrows we will use meshgrid() method of Numpy. First, create a set of arrays named X and Y which represent the starting positions of x and y respectively of each arrow on the quiver plot. The starting positions of x, y arrows can also be used to define the x and y components of each arrow direction. In the following plot u and v denote the array of directions of the quiver arrows and we will define the arrow direction based on the arrow starting point by using the equations below:
x_{direction} = cos(x_{starting \ point}) y_{direction} = sin(y_{starting \ point})
Example:
Python3
# Import libraries import numpy as np import matplotlib.pyplot as plt # Creating arrow x = np.arange( 0 , 2.2 , 0.2 ) y = np.arange( 0 , 2.2 , 0.2 ) X, Y = np.meshgrid(x, y) u = np.cos(X) * Y v = np.sin(Y) * Y # creating plot fig, ax = plt.subplots(figsize = ( 14 , 8 )) ax.quiver(X, Y, u, v) ax.xaxis.set_ticks([]) ax.yaxis.set_ticks([]) ax.axis([ - 0.3 , 2.3 , - 0.3 , 2.3 ]) ax.set_aspect( 'equal' ) # show plot plt.show() |
Output :
Quiver Plot in Matplotlib
Quiver plot is basically a type of 2D plot which shows vector lines as arrows. This type of plots are useful in Electrical engineers to visualize electrical potential and show stress gradients in Mechanical engineering.