Python | Dual Headed Arrow in Plots

In this tutorial, we are going to learn how to draw a dual headed arrow in python using matplotlib?
Submitted by Anuj Singh, on August 08, 2020

We can use a single-headed arrow function twice with precise positioning for plotting dual-headed arrows. The following example illustrates how we can use the function matplotlib.pyplot.arrow() to draw dual-headed arrows. Moreover, we can change the color as shown in the second example.

Example

Python | Dual Headed Arrow in Plots

Python code for dual headed arrow in plots

import matplotlib.pyplot as plt

# Arrows

plt.figure()
plt.title('The Dual Headed Arrow')
plt.arrow(0.3, 0.1, 0.4, 0.7, color='blue',
          head_length = 0.07, head_width = 0.025, 
          length_includes_head = True)

plt.arrow(0.7, 0.8, -0.4, -0.7, color='blue',
          head_length = 0.07, head_width = 0.025, 
          length_includes_head = True)
plt.show()

plt.figure()
plt.title('Two Dual Headed Arrow')
plt.arrow(0.3, 0.1, 0.4, 0.7, color='blue',
          head_length = 0.07, head_width = 0.025, 
          length_includes_head = True)

plt.arrow(0.7, 0.8, -0.4, -0.7, color='blue',
          head_length = 0.07, head_width = 0.025, 
          length_includes_head = True)

plt.arrow(0.2, 0.3, 0.7, 0.0, color='green',
          head_length = 0.07, head_width = 0.025, 
          length_includes_head = True)

plt.arrow(0.9, 0.3, -0.7, 0.0, color='green',
          head_length = 0.07, head_width = 0.025, 
          length_includes_head = True)
plt.show()

Output

Output is as Figure

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.