Matplotlib Arrows

import matplotlib.pyplot as plt

# Create a new figure
fig, ax = plt.subplots()

# Draw an arrow from (0, 0) to (1, 1)
ax.annotate('', xy=(1, 1), xytext=(0, 0),
            arrowprops=dict(facecolor='black', shrink=0.05))

# Set the limits of the plot
ax.set_xlim(-1, 2)
ax.set_ylim(-1, 2)

# Show the plot
plt.show()
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

# Customized arrow
ax.annotate(
    '',  
    xy=(0.5, 0.5),  
    xytext=(0, 0),  
    arrowprops=dict(
        facecolor='red',
        edgecolor='blue',
        linestyle='dotted',
        linewidth=2,
        arrowstyle='->',
        shrinkA=0, shrinkB=0
    )
)

ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
plt.show()
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
y = np.sin(x)

# Create a new figure
fig, ax = plt.subplots()
ax.plot(x, y, label='sin(x)')

# Annotate a specific point
ax.annotate('local max', xy=(np.pi/2, 1), xytext=(np.pi/2 + 1, 1.5),
            arrowprops=dict(facecolor='black', shrink=0.05))

# Set labels and legend
ax.set_xlabel('x')
ax.set_ylabel('sin(x)')
ax.legend()

# Show the plot
plt.show()
import matplotlib.pyplot as plt

# Create a new figure
fig, ax = plt.subplots()

# Arrow 1
ax.annotate('', xy=(1, 2), xytext=(0, 0),
            arrowprops=dict(facecolor='blue', shrink=0.05))

# Arrow 2
ax.annotate('', xy=(2, 1), xytext=(0, 0),
            arrowprops=dict(facecolor='red', shrink=0.05))

# Arrow 3
ax.annotate('', xy=(1, 1), xytext=(0, 0), 
            arrowprops=dict(facecolor='green', shrink=0.05))

# Set the limits of the plot
ax.set_xlim(-1, 3)
ax.set_ylim(-1, 3)

# Show the plot
plt.show()
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.annotate(
    'Arrow 1',  
    xy=(0.6, 0.6),  
    xytext=(0.3, 0.2),  
    arrowprops=dict(facecolor='magenta', arrowstyle='->', linewidth=2)
)

ax.annotate(
    'Arrow 2',  
    xy=(0.8, 0.2),  
    xytext=(0.5, 0.7),  
    arrowprops=dict(facecolor='cyan', arrowstyle='-[', linewidth=2)
)

ax.annotate(
    'Arrow 3',  
    xy=(0.2, 0.5),  
    xytext=(0.5, 0.1),  
    arrowprops=dict(facecolor='orange', arrowstyle='fancy', linewidth=2)
)

ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
plt.show()
CTRL + ENTER to send