Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.
matplotlib.axes.Axes.quiver() Function
The Axes.barbs() function in axes module of matplotlib library is also used to plot a 2D field of arrows.
Syntax: Axes.quiver(self, *args, data=None, **kw Parameters: This method accept the following parameters that are described below:
- X, Y : These parameter are the x and y coordinates of the arrow locations.
- U, V: These parameter are the x and y components of the arrow vector.
- C : This parameter contains the numeric data that defines the arrow colors by colormapping via norm and cmap.
- pivot : This parameter is the part of the arrow that is anchored to the X, Y grid.
- units : This parameter is the arrow dimensions (except for length) are measured in multiples of this unit.
- angles : This parameter is the method for determining the angle of the arrows.
- scale : This parameter is the number of data units per arrow length unit.
- scale_units : This parameter is an optional parameter and it contains these values ‘width’, ‘height’, ‘dots’, ‘inches’, ‘x’, ‘y’, ‘xy’ .
- width : This parameter is the shaft width in arrow units.
- headwidth : This parameter is the head width as multiple of shaft width.
- headlength : This parameter is the length width as multiple of shaft width.
- headwidth : This parameter is the head width as multiple of shaft width.
- headaxislength : This parameter is the head length at shaft intersection.
- minshaft : This parameter is the length below which arrow scales, in units of head length.
- minlength : This parameter is the minimum length as a multiple of shaft width.
- color : This parameter is the explicit color(s) for the arrows.
Below examples illustrate the matplotlib.axes.Axes.quiver() function in matplotlib.axes: Example 1:
Python3
# Implementation of matplotlib function import matplotlib.pyplot as plt import numpy as np X = np.arange( - 20 , 20 , 0.5 ) Y = np.arange( - 20 , 20 , 0.5 ) U, V = np.meshgrid(X, Y) fig, ax = plt.subplots() q = ax.quiver(X, Y, U, V) ax.set_title('matplotlib.axes.Axes.quiver()\ Example ', fontsize = 14, fontweight =' bold') plt.show() |
Output: Example 2:
Python3
# Implementation of matplotlib function import matplotlib.pyplot as plt import numpy as np X, Y = np.meshgrid(np.arange( 0 , 2 * np.pi, . 2 ), np.arange( 0 , 2 * np.pi, . 2 )) U = np.cos(X * * 2 ) V = np.sin(Y * * 2 ) C = U * * 2 + V * * 2 fig, ax = plt.subplots() ax.quiver(X, Y, U, V, C, units = 'width' ) ax.set_title('matplotlib.axes.Axes.quiver() \ Example ', fontsize = 14, fontweight =' bold') plt.show() |
Output: