Creating a Quiver Plot
Let’s start creating a simple quiver plot containing one arrow which will explain how Matplotlib’s ax.quiver() function works. The ax.quiver() function takes four arguments:
Syntax:
ax.quiver(x_pos, y_pos, x_dir, y_dir, color)
Here x_pos and y_pos are the starting positions of the arrow while x_dir and y_dir are the directions of the arrow.
The below plot contains one quiver arrow starting at x_pos = 0 and y_pos = 0.The direction of the arrow is pointing towards up and the right at x_dir = 1 and y_dir = 1.
Example:
Python3
# Import libraries import numpy as np import matplotlib.pyplot as plt # Creating arrow x_pos = 0 y_pos = 0 x_direct = 1 y_direct = 1 # Creating plot fig, ax = plt.subplots(figsize = ( 12 , 7 )) ax.quiver(x_pos, y_pos, x_direct, y_direct) ax.set_title( 'Quiver plot with one arrow' ) # 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.
Contact Us