How to make simple double head arrows on the axes in Matplotlib?

Creating double head arrows on Matplotlib axes helps visualize relationships and measurements between points. You can achieve this using the annotate() method with specific arrow properties.

Basic Double Head Arrow

Use the annotate() method with arrowstyle="<->" to create arrows pointing in both directions ?

import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

plt.annotate('Double Arrow', xy=(0.1, 0.1), xytext=(0.5, 0.5),
             arrowprops=dict(arrowstyle='<->', color='red'))

plt.show()

Customizing Arrow Properties

You can customize the arrow appearance by modifying properties like color, line width, and style ?

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(8, 6))

# Multiple arrows with different styles
plt.annotate('Arrow 1', xy=(0.2, 0.2), xytext=(0.8, 0.8),
             arrowprops=dict(arrowstyle='<->', color='blue', lw=2))

plt.annotate('Arrow 2', xy=(0.8, 0.2), xytext=(0.2, 0.8),
             arrowprops=dict(arrowstyle='<->', color='green', lw=3))

plt.annotate('Arrow 3', xy=(0.1, 0.5), xytext=(0.9, 0.5),
             arrowprops=dict(arrowstyle='<->', color='purple', lw=1.5))

ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
plt.title('Multiple Double Head Arrows')
plt.show()

Arrow Parameters

Parameter Description Example Values
xy Arrow starting point (0.1, 0.1)
xytext Arrow ending point (0.5, 0.5)
arrowstyle Arrow head style '<->', '->', '<-'
color Arrow color 'red', 'blue', '#FF5733'
lw Line width 1, 2, 3

Practical Example with Data Points

Here's how to use double head arrows to show relationships between actual data points ?

import matplotlib.pyplot as plt
import numpy as np

# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 4, 1, 5, 3]

fig, ax = plt.subplots(figsize=(8, 6))

# Plot the data points
ax.scatter(x, y, color='black', s=50, zorder=3)

# Add double head arrows between specific points
ax.annotate('', xy=(x[0], y[0]), xytext=(x[1], y[1]),
            arrowprops=dict(arrowstyle='<->', color='red', lw=2))

ax.annotate('Distance', xy=(1.5, 3.2), xytext=(1.5, 3.2),
            fontsize=12, ha='center')

ax.set_xlabel('X Values')
ax.set_ylabel('Y Values')
ax.set_title('Double Head Arrow Between Data Points')
ax.grid(True, alpha=0.3)
plt.show()

Conclusion

Double head arrows in Matplotlib are created using annotate() with arrowstyle="<->". Customize appearance using color, line width, and positioning parameters to effectively visualize relationships between data points.

Updated on: 2026-03-25T23:00:00+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements