matplotlib.pyplot.arrow() in Python (original) (raw)

Last Updated : 07 Apr, 2025

**Matplotlib is a very powerful plotting library Python, widely used for data visualization and statistical analysis. One of its useful functions is **arrow(), which lets you add arrows to your plots to highlight or point out specific data points or trends.

This article explains how to use the **arrow() function, its syntax and how to customize arrows using various parameters.

Example 1: Basic Arrow Addition

This example shows how to add a simple arrow to a plot.

Python `

import matplotlib.pyplot as plt

Data points

x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10]

Plot the data

plt.plot(x, y)

Add an arrow starting at (2, 4) with dx = 2 and dy = 2, and a specified width

plt.arrow(2, 4, 2, 2, width=0.05)

Display the plot

plt.show()

`

**Output:

matplotlib.pyplot.arrow()

**Explanation:

Syntax

matplotlib.pyplot.arrow(x, y, dx, dy, **kwargs)

**Parameters:

Examples of arrow() function

Example 1 : Adjusting Arrow Head Width

This example demonstrates how to increase the arrowhead width for better visibility.

Python `

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] plt.plot(x, y)

Add an arrow with a larger head width (0.2) and a shaft width of 0.05

plt.arrow(2, 4, 2, 2, head_width=0.2, width=0.05)

plt.show()

`

**Output:

matplotlib.pyplot.arrow()

**Explanation:

Example 2: Changing Arrow Edge Color

This example shows how to change the arrow’s edge color to green.

Python `

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] plt.plot(x, y)

Add an arrow with a green edge color

plt.arrow(2, 4, 2, 2, head_width=0.2, width=0.05, ec='green')

plt.show()

`

**Output:

matplotlib.pyplot.arrow()

**Explanation: