The Wayback Machine - https://web.archive.org/web/20240619225217/https://www.geeksforgeeks.org/matplotlib-pyplot-arrow-in-python/
Open In App

matplotlib.pyplot.arrow() in Python

Last Updated : 20 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Matplotlib is a very powerful plotting library useful for those working with Python and NumPy. And for making statistical interference, it becomes very necessary to visualize our data and Matplotlib is the tool that can be very helpful for this purpose. It provides MATLAB like interface only difference is that it uses Python and is open source.

matplotlib.pyplot.arrow()

This function adds the arrow to the graph based on the coordinates passed to it. 

Syntax: matplotlib.pyplot.arrow(x, y, dx, dy, **kwargs)
Parameters: 
x, y: The x and y coordinates of the arrow base. 
dx, dy: The length of the arrow along x and y direction. 
**kwargs: Optional arguments that helps in adding properties to arrow, like 
adding color to arrow, changing width of arrow 
 

Example #1  

Python3




import matplotlib.pyplot as plt
 
 
# Initializing values
# of x and y
x =[1, 2, 3, 4, 5]
y =[2, 4, 6, 8, 10]
 
# Plotting the graph
plt.plot(x, y)
 
# Adding an arrow to graph starting
# from the base (2, 4) and with the
# length of 2 units from both x and y
# And setting the width of arrow for
# better visualization
plt.arrow(2, 4, 2, 2, width = 0.05)
 
# Showing the graph
plt.show()


Output: 

matplotlib.pyplot.arrow()

Example 2#  

Python3




import matplotlib.pyplot as plt
 
 
x =[1, 2, 3, 4, 5]
y =[2, 4, 6, 8, 10]
 
plt.plot(x, y)
 
# Increasing head_width of
# the arrow by setting
# head_width parameter
plt.arrow(2, 4, 2, 2,
          head_width = 0.2,
          width = 0.05)
 
plt.show()


Output: 

matplotlib.pyplot.arrow()

Example #3  

Python3




import matplotlib.pyplot as plt
 
 
x =[1, 2, 3, 4, 5]
y =[2, 4, 6, 8, 10]
plt.plot(x, y)
 
# changing the edge color
# to green
plt.arrow(2, 4, 2, 2,
          head_width = 0.2,
          width = 0.05,
          ec ='green')
 
plt.show()


Output: 

matplotlib.pyplot.arrow()

 



Similar Reads

Matplotlib.axes.Axes.arrow() in Python
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.arrow() Function The Axes.arr
2 min read
Matplotlib.patches.Arrow Class in Python
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. Matplotlib.patches.Arrow The matplotlib.patches.Arrow class is used to for patching an arrow in the plot. it draws arrow from (x, y) to (x
3 min read
Matplotlib.pyplot.broken_barh() in Python
Matplotlib is one of the most popular Python packages used for data visualization. It is a cross-platform library for making 2D plots from data in arrays. Pyplot is a collection of command style functions that make matplotlib work like MATLAB. matplotlib.pyplot.broken_barh() The function broken_barh() is used to Plot a horizontal sequence of rectan
2 min read
Matplotlib.pyplot.axis() in Python
Matplotlib is a plotting library for creating static, animated, and interactive visualizations in Python. Pyplot is a Matplotlib module which provides a MATLAB-like interface. Matplotlib is designed to be as usable as MATLAB, with the ability to use Python and the advantage of being free and open-source. matplotlib.pyplot.axis() This function is us
1 min read
Matplotlib.pyplot.get_fignums() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, etc. matplotlib.pyplot.get_fignums() method The ge
2 min read
Python | Matplotlib.pyplot ticks
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. It was introduced by John Hunter in the year 2003.One of the greatest benefits of visualization is that it allows us visual access to huge
3 min read
Matplotlib.pyplot.waitforbuttonpress() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, etc. matplotlib.pyplot.waitforbuttonpress() method
2 min read
Matplotlib.pyplot.streamplot() in Python
Stream plot is basically a type of 2D plot used majorly by physicists to show fluid flow and 2D field gradients .The basic function to create a stream plot in Matplotlib is: ax.streamplot(x_grid, y_grid, x_vec, y_vec, density=spacing) Here x_grid and y_grid are arrays of the x and y points.The x_vec and y_vec represent the stream velocity of each p
7 min read
Matplotlib.pyplot.ylim() in Python
Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.ylim() Function The ylim() function in pyplot module of matplotlib library is used to get or set the y-limits of the current axes. Syntax
2 min read
Matplotlib.pyplot.figimage() function in Python
Matplotlib is a widely used library in Python for plotting various graphs, as it provides very efficient ways and easy to understand methods for complex plots also. pyplot is a collection of command style functions that make matplotlib work like MATLAB. figimage() function matplotlib.pyplot.figimage() is a method for adding a non-resampled image to
2 min read
Article Tags :
Practice Tags :