In Matplotlib, barbs
are arrowheads with a dark projection at their head. They're used to show magnitude and direction while a barbs
plot is used to plot barbs
in the cartesian plane.
Matplotlib has a class named Axes
, which helps in the coordination system and supports callbacks throughout the functions. In axes.barbs()
, the axes
class is used to generate a 2-D field of barbs
.
barbs([X, Y], U, V, [C], **kw)
[X, Y]
: These are the x and y coordinates of barbs locations.U
: This is the barb direction along with the x component.V
: This is the barb direction along with the y component.[C]
: This is used to add colors to barbs.**kw
: These are some additional argument values.It returns an instance of barbs
type.
# import pyplot from matplotlib & numpy libraryimport matplotlib.pyplot as pltimport numpy as np# evenly spaced numbers between 10 and 30x = np.linspace(10, 30, 15)# It will create a figure & a set of subplotsfig, axis = plt.subplots()# creating barbs plotaxis.barbs(x**5, x**3, x * 3, x * 2, x * 4)# set title for above created graphaxis.set_title('Barbs Graph Example', fontsize = 16, fontweight ='bold')# save the current figureplt.savefig('output/graph.png')
np.linspace(10, 30, 15)
to create an Ndarray where 10
shows the starting value, 30
shows the ending value, and 15
shows the number of samples. Therefore, it creates evenly spread numeric values for the plot.plt.subplots()
method returns a figure and axis type instance of a frame to show the graph. We use it to describe the layout of the plot.axis.barbs()
method to generate a barbs plot on random values.'Barbs Graph Example'
with fontsize = 16
and fontweight ='bold'
.