Line plot with arrows in Matplotlib

To plot with arrows in matplotlib, we can use arrow() method.


  • Create x and y data points using numpy.
  • Plot x and y with color=red and linewidth = 1.
  • Use arrow method to add an arrow to the axes. The first two values in the arguments are the coordinates of the arrow base and the next two values are for the length of the arrow along X and Y direction.
  • To display the figure, use show() method.


from matplotlib import pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(-2, 2, 100)
y = np.sin(x)
plt.plot(x, y, c='b', lw=1)
plt.arrow(0, 0, 0.01, np.sin(0.01), shape='full', lw=10,
   length_includes_head=True, head_width=.05, color='r')


Updated on: 07-May-2021

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started