Open In App

Matplotlib.axes.Axes.barbs() in Python

Last Updated : 28 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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.barbs() Function

The Axes.barbs() function in axes module of matplotlib library is also used to plot a 2D field of barbs.

Syntax: Axes.barbs(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 barb locations.
  • U, V: These parameter are the x and y components of the barb shaft.
  • C : This parameter contains the numeric data that defines the barb colors by colormapping via norm and cmap.
  • length : This parameter is the length of the barb in points.
  • pivot : This parameter is the part of the arrow that is anchored to the X, Y grid.
  • barbcolor : This parameter is analogous to the edgecolor parameter for polygons, which can be used instead.
  • flagcolor : This parameter is analogous to the facecolor parameter for polygons.
  • sizes : This parameter is the dictionary of coefficients specifying the ratio of a given feature to the length of the barb.
  • fill_empty : This parameter is used to fill the empty barbs with the flag color.
  • barb_increments : This parameter is the dictionary of increments specifying values to associate with different parts of the barb.
  • flip_barb : This parameter is the single value is applied to all barbs.

Returns: This method returns the following:

  • barbs : This return the Barbs.

Note: This function works in Matplotlib version >= 3.1 Below examples illustrate the matplotlib.axes.Axes.barbs() function in matplotlib.axes: Example 1: 

Python3




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
     
x = np.linspace(0, 15, 5)
 
fig1, axs1 = plt.subplots()
axs1.barbs(x**3, x**3, x * 2, x * 2, x * 3,
           fill_empty = True)
 
axs1.set_title('matplotlib.axes.Axes.barbs()\
 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 = np.linspace(0, 15, 5)
X, Y = np.meshgrid(x, x)
U, V = X**2, Y**2
 
fig1, axs1 = plt.subplots()
axs1.barbs(X, Y, U, V, U * 2, fill_empty = True)
 
axs1.set_title('matplotlib.axes.Axes.barbs()\
 Example', fontsize = 14, fontweight ='bold')
plt.show()


Output:

 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads