Quiver Plot with two arrows
Let’s add another arrow to the plot passing through two starting points and two directions. By keeping the original arrow starting at origin(0, 0) and pointing towards up and to the right direction(1, 1), and create the second arrow starting at (0, 0) pointing down in direction(0, -1).To see the starting and ending point clearly, we will set axis limits to [-1.5, 1.5] using the method ax.axis() and passing the arguments in the form of [x_min, x_max, y_max, y_min] . By adding an additional argument scale=value to the ax.quiver() method we can manage the lengths of the arrows to look longer and show up better on the plot.
Example:
Python3
# Import libraries import numpy as np import matplotlib.pyplot as plt # Creating arrow x_pos = [ 0 , 0 ] y_pos = [ 0 , 0 ] x_direct = [ 1 , 0 ] y_direct = [ 1 , - 1 ] # Creating plot fig, ax = plt.subplots(figsize = ( 12 , 7 )) ax.quiver(x_pos, y_pos, x_direct, y_direct, scale = 5 ) ax.axis([ - 1.5 , 1.5 , - 1.5 , 1.5 ]) # 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.